1 // Copyright 2006 The Android Open Source Project 2 3 #ifndef DMTRACE_H 4 #define DMTRACE_H 5 6 #include <vector> 7 8 class DmTrace { 9 public: 10 struct Header { 11 uint32_t magic; 12 uint16_t version; 13 uint16_t offset; 14 uint64_t date_time; 15 }; 16 17 DmTrace(); 18 ~DmTrace(); 19 20 void open(const char *dmtrace_file, uint64_t startTime); 21 void close(); 22 void addFunctionEntry(int methodId, uint32_t cycle, uint32_t pid); 23 void addFunctionExit(int methodId, uint32_t cycle, uint32_t pid); 24 void addFunction(int functionId, const char *name); 25 void addFunction(int functionId, const char *clazz, const char *method, 26 const char *sig); 27 void parseAndAddFunction(int functionId, const char *name); 28 void addThread(int threadId, const char *name); 29 void updateName(int threadId, const char *name); 30 31 private: 32 static const Header header; 33 34 struct ThreadRecord { 35 int id; 36 const char *name; 37 }; 38 39 struct FunctionRecord { 40 int id; 41 const char *name; 42 }; 43 44 void write2LE(FILE* fstream, unsigned short val); 45 void write4LE(FILE* fstream, unsigned int val); 46 void write8LE(FILE* fstream, unsigned long long val); 47 void writeHeader(FILE *fstream, uint64_t startTime); 48 void writeDataRecord(FILE *fstream, int threadId, 49 unsigned int methodVal, 50 unsigned int elapsedTime); 51 void writeKeyFile(FILE *fstream); 52 void writeThreads(FILE *fstream); 53 void writeFunctions(FILE *fstream); 54 55 FILE *fData; 56 FILE *fTrace; 57 std::vector<ThreadRecord*> *threads; 58 std::vector<FunctionRecord*> *functions; 59 }; 60 61 #endif // DMTRACE_H 62