tools/jprof/leaky.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:72f8df5f7bfc
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #ifndef __leaky_h_
6 #define __leaky_h_
7
8 #include "config.h"
9 #include <stdio.h>
10 #include <string.h>
11 #include <sys/types.h>
12 #include "libmalloc.h"
13 #include "strset.h"
14 #include "intcnt.h"
15
16 typedef unsigned int u_int;
17
18 struct Symbol;
19 struct leaky;
20
21 class FunctionCount : public IntCount
22 {
23 public:
24 void printReport(FILE *fp, leaky *lk, int parent, int total);
25 };
26
27 struct Symbol {
28 char* name;
29 u_long address;
30 int timerHit;
31 FunctionCount cntP, cntC;
32
33 int regChild(int id) {return cntC.countAdd(id, 1);}
34 int regParrent(int id) {return cntP.countAdd(id, 1);}
35 void regClear() {cntC.clear(); cntP.clear();}
36
37 Symbol() : timerHit(0) {}
38 void Init(const char* aName, u_long aAddress) {
39 name = aName ? strdup(aName) : (char *)"";
40 address = aAddress;
41 }
42 };
43
44 struct LoadMapEntry {
45 char* name; // name of .so
46 u_long address; // base address where it was mapped in
47 LoadMapEntry* next;
48 };
49
50 struct leaky {
51 leaky();
52 ~leaky();
53
54 void initialize(int argc, char** argv);
55 void open(char *arg);
56
57 char* applicationName;
58 int logFileIndex;
59 int numLogFiles;
60 char* progFile;
61 FILE* outputfd;
62
63 bool quiet;
64 bool showAddress;
65 bool showThreads;
66 bool cleo;
67 u_int stackDepth;
68 int onlyThread;
69 char* output_dir;
70
71 int mappedLogFile;
72 malloc_log_entry* firstLogEntry;
73 malloc_log_entry* lastLogEntry;
74
75 int stacks;
76
77 int sfd;
78 Symbol** externalSymbols;
79 Symbol** lastSymbol;
80 int usefulSymbols;
81 int numExternalSymbols;
82 StrSet exclusions;
83 u_long lowestSymbolAddr;
84 u_long highestSymbolAddr;
85
86 LoadMapEntry* loadMap;
87
88 bool collect_last;
89 int collect_start;
90 int collect_end;
91
92 StrSet roots;
93 StrSet includes;
94
95 void usageError();
96
97 void LoadMap();
98
99 void analyze(int thread);
100
101 void dumpEntryToLog(malloc_log_entry* lep);
102
103 void insertAddress(u_long address, malloc_log_entry* lep);
104 void removeAddress(u_long address, malloc_log_entry* lep);
105
106 void displayStackTrace(FILE* out, malloc_log_entry* lep);
107
108 Symbol ** ExtendSymbols(int num);
109 void ReadSymbols(const char* fileName, u_long aBaseAddress);
110 void ReadSharedLibrarySymbols();
111 void setupSymbols(const char* fileName);
112 Symbol* findSymbol(u_long address);
113 bool excluded(malloc_log_entry* lep);
114 bool included(malloc_log_entry* lep);
115 const char* indexToName(int idx) {return externalSymbols[idx]->name;}
116
117 private:
118 void generateReportHTML(FILE *fp, int *countArray, int count, int thread);
119 int findSymbolIndex(u_long address);
120 };
121
122 #endif /* __leaky_h_ */

mercurial