| 1 | #ifndef READER_H
|
|---|
| 2 | #define READER_H 1
|
|---|
| 3 | #include <signal.h>
|
|---|
| 4 | #include <sys/types.h>
|
|---|
| 5 | #include <unistd.h>
|
|---|
| 6 | #include <iostream>
|
|---|
| 7 | #include <iomanip>
|
|---|
| 8 | #include <string>
|
|---|
| 9 | #include <stdexcept>
|
|---|
| 10 | #include <stack>
|
|---|
| 11 | #include <vector>
|
|---|
| 12 | #include <map>
|
|---|
| 13 | #include <set>
|
|---|
| 14 | #include <iterator>
|
|---|
| 15 | #include "numeric-utils.h"
|
|---|
| 16 |
|
|---|
| 17 | struct TapenadeLogReaderImpl;
|
|---|
| 18 | enum TapenadeLogEventKind {
|
|---|
| 19 | BEGIN = 1,
|
|---|
| 20 | END = 2,
|
|---|
| 21 | ENDFWD = 3,
|
|---|
| 22 | BEGINSNAP = 4,
|
|---|
| 23 | ENDSNAP = 5,
|
|---|
| 24 | ENDORIG = 6
|
|---|
| 25 | };
|
|---|
| 26 |
|
|---|
| 27 | class TapenadeLogEvent
|
|---|
| 28 | {
|
|---|
| 29 | public:
|
|---|
| 30 | std::string &function_name;
|
|---|
| 31 | unsigned int kind;
|
|---|
| 32 | unsigned long long int time;
|
|---|
| 33 | unsigned int size;
|
|---|
| 34 | TapenadeLogEvent(std::string &_function_name ,unsigned int _kind,
|
|---|
| 35 | unsigned long long int _time, unsigned int _size) :
|
|---|
| 36 | function_name(_function_name),
|
|---|
| 37 | kind(_kind),
|
|---|
| 38 | time(_time),
|
|---|
| 39 | size(_size)
|
|---|
| 40 | { }
|
|---|
| 41 | bool operator==(const TapenadeLogEvent &that)
|
|---|
| 42 | {
|
|---|
| 43 | return (function_name == that.function_name) &&
|
|---|
| 44 | (kind = that.kind) &&
|
|---|
| 45 | (time == that.time) &&
|
|---|
| 46 | (size == that.size);
|
|---|
| 47 | }
|
|---|
| 48 | TapenadeLogEvent &operator=(const TapenadeLogEvent &other)
|
|---|
| 49 | {
|
|---|
| 50 | function_name = other.function_name;
|
|---|
| 51 | kind = other.kind;
|
|---|
| 52 | time = other.time;
|
|---|
| 53 | size = other.size;
|
|---|
| 54 | }
|
|---|
| 55 | std::string &get_function_name()
|
|---|
| 56 | {
|
|---|
| 57 | return function_name;
|
|---|
| 58 | }
|
|---|
| 59 | unsigned int get_kind()
|
|---|
| 60 | {
|
|---|
| 61 | return kind;
|
|---|
| 62 | }
|
|---|
| 63 | unsigned long long int get_time()
|
|---|
| 64 | {
|
|---|
| 65 | return time;
|
|---|
| 66 | }
|
|---|
| 67 | unsigned int get_size()
|
|---|
| 68 | {
|
|---|
| 69 | return size;
|
|---|
| 70 | }
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | inline std::ostream &operator<<(std::ostream &o, TapenadeLogEvent &event)
|
|---|
| 74 | {
|
|---|
| 75 | using namespace std;
|
|---|
| 76 | char s = ' ';
|
|---|
| 77 | o << setw(14) << event.time << s;
|
|---|
| 78 | o << setw(9) << event.size << s;
|
|---|
| 79 | o << setw(2) << event.kind << s;
|
|---|
| 80 | o << event.function_name;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | class TapenadeLogReader
|
|---|
| 84 | {
|
|---|
| 85 | const std::string filename;
|
|---|
| 86 | bool ok;
|
|---|
| 87 | bool initialized;
|
|---|
| 88 | TapenadeLogReaderImpl *impl;
|
|---|
| 89 | public:
|
|---|
| 90 | TapenadeLogReader(const std::string &_filename) : filename(_filename), ok(true), initialized(false)
|
|---|
| 91 | { }
|
|---|
| 92 | TapenadeLogEvent readEvent() throw (std::runtime_error);
|
|---|
| 93 | bool eof() throw (std::runtime_error);
|
|---|
| 94 | ~TapenadeLogReader();
|
|---|
| 95 | };
|
|---|
| 96 | class ReadingOnlyInAdjointBranch
|
|---|
| 97 | {
|
|---|
| 98 | bool unread;
|
|---|
| 99 | bool done ;
|
|---|
| 100 | TapenadeLogEvent *unreadEvent;
|
|---|
| 101 | bool adjoint_branch ;
|
|---|
| 102 | std::string adjoint_branch_first_function_name;
|
|---|
| 103 | int adjoint_branch_first_function_recursion ;
|
|---|
| 104 | TapenadeLogReader *reader;
|
|---|
| 105 | public:
|
|---|
| 106 | ReadingOnlyInAdjointBranch(const std::string &);
|
|---|
| 107 | ~ReadingOnlyInAdjointBranch();
|
|---|
| 108 | bool eof() throw(std::runtime_error);
|
|---|
| 109 | TapenadeLogEvent readEvent() throw(std::runtime_error);
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | #endif
|
|---|