| 1 | #include "reader.h"
|
|---|
| 2 | #include <fstream>
|
|---|
| 3 | #include <string>
|
|---|
| 4 | #include <stdexcept>
|
|---|
| 5 | #include <map>
|
|---|
| 6 | #include <stack>
|
|---|
| 7 | #include <set>
|
|---|
| 8 | #include <iostream>
|
|---|
| 9 | #include <iomanip>
|
|---|
| 10 | #include <algorithm>
|
|---|
| 11 | #include <functional>
|
|---|
| 12 | #include <memory>
|
|---|
| 13 | #include <iterator>
|
|---|
| 14 | #include <limits>
|
|---|
| 15 |
|
|---|
| 16 | using namespace std;
|
|---|
| 17 |
|
|---|
| 18 | typedef unsigned long long int clicks;
|
|---|
| 19 |
|
|---|
| 20 | int main(int argc, char **argv)
|
|---|
| 21 | {
|
|---|
| 22 | bool remove_subtime = true;
|
|---|
| 23 | beginning:
|
|---|
| 24 | if (argc < 3) {
|
|---|
| 25 | cout << "Usage: profile tapenade.prof ouput.csv\n";
|
|---|
| 26 | exit(-1);
|
|---|
| 27 | }
|
|---|
| 28 | if (string("-nosubtime") == argv[1]) {
|
|---|
| 29 | remove_subtime = false;
|
|---|
| 30 | argv[1] = argv[2];
|
|---|
| 31 | argv[2] = argv[3];
|
|---|
| 32 | main(argc, argv);
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|
| 35 | const string filename(argv[1]);
|
|---|
| 36 | ReadingOnlyInAdjointBranch reader(filename);
|
|---|
| 37 |
|
|---|
| 38 | stack<TapenadeLogEvent> call_stack;
|
|---|
| 39 | int first_free_function_id = 0;
|
|---|
| 40 | map<string,int> function_ids;
|
|---|
| 41 | typedef map<string, int> functions_ids_t;
|
|---|
| 42 | typedef functions_ids_t::iterator ids_iter;
|
|---|
| 43 | vector<int> taping;
|
|---|
| 44 | vector<int> snapshoting;
|
|---|
| 45 | vector<clicks> snapshottime;
|
|---|
| 46 | vector<clicks> fwdtime;
|
|---|
| 47 | vector<clicks> totaltime;
|
|---|
| 48 | vector<int> totalsize;
|
|---|
| 49 | vector<int> call_count;
|
|---|
| 50 | vector<int> snap_count;
|
|---|
| 51 | stack<clicks> subtime;
|
|---|
| 52 |
|
|---|
| 53 | taping.reserve(2000);
|
|---|
| 54 | fwdtime.reserve(2000);
|
|---|
| 55 | snap_count.reserve(2000);
|
|---|
| 56 | snapshoting.reserve(2000);
|
|---|
| 57 | snapshottime.reserve(2000);
|
|---|
| 58 | call_count.reserve(2000);
|
|---|
| 59 | totalsize.reserve(2000);
|
|---|
| 60 | totaltime.reserve(2000);
|
|---|
| 61 | int event_count = 0;
|
|---|
| 62 | while (! reader.eof()) {
|
|---|
| 63 | TapenadeLogEvent event(reader.readEvent());
|
|---|
| 64 | int kind = event.get_kind();
|
|---|
| 65 | switch(kind) {
|
|---|
| 66 | case BEGIN:
|
|---|
| 67 | subtime.push(0);
|
|---|
| 68 | call_stack.push(event);
|
|---|
| 69 | break;
|
|---|
| 70 | case BEGINSNAP:
|
|---|
| 71 | call_stack.push(event);
|
|---|
| 72 | break;
|
|---|
| 73 | }
|
|---|
| 74 | string &name = event.get_function_name();
|
|---|
| 75 | clicks time = event.get_time();
|
|---|
| 76 | unsigned int size = event.get_size();
|
|---|
| 77 | // Allocate a function id if necessary
|
|---|
| 78 | unsigned int id;
|
|---|
| 79 | if (function_ids.find(name) == function_ids.end()) {
|
|---|
| 80 | id = first_free_function_id++;
|
|---|
| 81 | function_ids[name] = id;
|
|---|
| 82 |
|
|---|
| 83 | taping[id] = 0;
|
|---|
| 84 | fwdtime[id] = 0;
|
|---|
| 85 | snap_count[id] = 0;
|
|---|
| 86 | snapshoting[id] = 0;
|
|---|
| 87 | snapshottime[id] = 0;
|
|---|
| 88 | call_count[id] = 0;
|
|---|
| 89 | totalsize[id] = 0;
|
|---|
| 90 | totaltime[id] = 0;
|
|---|
| 91 | }
|
|---|
| 92 | else
|
|---|
| 93 | id = function_ids[name];
|
|---|
| 94 |
|
|---|
| 95 | // ALLOCATE
|
|---|
| 96 | // JOINT MODE taping & time
|
|---|
| 97 | if (kind == ENDFWD) {
|
|---|
| 98 | taping[id] += size-call_stack.top().get_size();
|
|---|
| 99 | fwdtime[id] += time-call_stack.top().get_time();
|
|---|
| 100 | }
|
|---|
| 101 | // SNAPSHOT taping & time
|
|---|
| 102 | if (kind == ENDSNAP) {
|
|---|
| 103 | snap_count[id]++;
|
|---|
| 104 | snapshoting[id] += size-call_stack.top().get_size();
|
|---|
| 105 | snapshottime[id] += size-call_stack.top().get_size();
|
|---|
| 106 | }
|
|---|
| 107 | // ORIG, FWD, BWD taping & time
|
|---|
| 108 | if (kind == END) {
|
|---|
| 109 | call_count[id]++;
|
|---|
| 110 | totalsize[id] += size-call_stack.top().get_size();
|
|---|
| 111 | clicks t = time-call_stack.top().get_time();
|
|---|
| 112 | totaltime[id] += t + (remove_subtime ? - subtime.top() : 0 );
|
|---|
| 113 | subtime.pop();
|
|---|
| 114 | if (subtime.size())
|
|---|
| 115 | subtime.top() += t;
|
|---|
| 116 | }
|
|---|
| 117 | switch(event.kind) {
|
|---|
| 118 | case ENDSNAP:
|
|---|
| 119 | call_stack.pop();
|
|---|
| 120 | break;
|
|---|
| 121 | case END:
|
|---|
| 122 | call_stack.pop();
|
|---|
| 123 | break;
|
|---|
| 124 | }
|
|---|
| 125 | event_count ++;
|
|---|
| 126 | }
|
|---|
| 127 | ofstream output_stream(argv[2]);
|
|---|
| 128 | ids_iter cur = function_ids.begin(), end = function_ids.end();
|
|---|
| 129 | output_stream << setw(25) << "name" ; // 1
|
|---|
| 130 | output_stream << setw(14) << "call_count" ; // 2
|
|---|
| 131 | output_stream << setw(14) << "snap_count" ; // 3
|
|---|
| 132 | output_stream << setw(14) << "taping" ; // 4
|
|---|
| 133 | output_stream << setw(14) << "snapshoting" ; // 5
|
|---|
| 134 |
|
|---|
| 135 | output_stream << setw(14) << "fwdtime" ; // 6
|
|---|
| 136 | output_stream << setw(14) << "totaltime" ; // 7
|
|---|
| 137 | output_stream << setw(14) << "totalsize" ; // 8
|
|---|
| 138 | output_stream << setw(14) << "snapshottime" ; // 8
|
|---|
| 139 | output_stream << endl;
|
|---|
| 140 | for (; cur != end; ++cur) {
|
|---|
| 141 | const string &name = (*cur).first;
|
|---|
| 142 | int id = (*cur).second;
|
|---|
| 143 | output_stream << setw(25) << name ; // 1
|
|---|
| 144 | output_stream << setw(14) << call_count[id]; // 2
|
|---|
| 145 | output_stream << setw(14) << snap_count[id]; // 3
|
|---|
| 146 | output_stream << setw(14) << taping[id]; // 4
|
|---|
| 147 | output_stream << setw(14) << snapshoting[id]; // 5
|
|---|
| 148 |
|
|---|
| 149 | output_stream << setw(14) << fwdtime[id]; // 6
|
|---|
| 150 | output_stream << setw(14) << totaltime[id]; // 7
|
|---|
| 151 | output_stream << setw(14) << totalsize[id]; // 8
|
|---|
| 152 | output_stream << setw(14) << snapshottime[id]; // 8
|
|---|
| 153 | output_stream << endl;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|