2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
#ifndef __leaky_h_
|
|
|
|
#define __leaky_h_
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "libmalloc.h"
|
|
|
|
#include "strset.h"
|
|
|
|
#include "intcnt.h"
|
|
|
|
|
|
|
|
typedef unsigned int u_int;
|
|
|
|
|
|
|
|
struct Symbol;
|
|
|
|
struct leaky;
|
|
|
|
|
|
|
|
class FunctionCount : public IntCount
|
|
|
|
{
|
|
|
|
public:
|
2011-05-15 13:47:48 +04:00
|
|
|
void printReport(FILE *fp, leaky *lk, int parent, int total);
|
2000-01-18 06:43:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Symbol {
|
|
|
|
char* name;
|
|
|
|
u_long address;
|
|
|
|
int timerHit;
|
|
|
|
FunctionCount cntP, cntC;
|
|
|
|
|
|
|
|
int regChild(int id) {return cntC.countAdd(id, 1);}
|
|
|
|
int regParrent(int id) {return cntP.countAdd(id, 1);}
|
2011-08-12 19:59:17 +04:00
|
|
|
void regClear() {cntC.clear(); cntP.clear();}
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
Symbol() : timerHit(0) {}
|
|
|
|
void Init(const char* aName, u_long aAddress) {
|
|
|
|
name = aName ? strdup(aName) : (char *)"";
|
|
|
|
address = aAddress;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LoadMapEntry {
|
|
|
|
char* name; // name of .so
|
|
|
|
u_long address; // base address where it was mapped in
|
|
|
|
LoadMapEntry* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct leaky {
|
|
|
|
leaky();
|
|
|
|
~leaky();
|
|
|
|
|
|
|
|
void initialize(int argc, char** argv);
|
2011-08-12 19:59:20 +04:00
|
|
|
void open(char *arg);
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
char* applicationName;
|
2011-08-12 19:59:20 +04:00
|
|
|
int logFileIndex;
|
|
|
|
int numLogFiles;
|
2000-01-18 06:43:26 +03:00
|
|
|
char* progFile;
|
2011-08-12 19:59:20 +04:00
|
|
|
FILE* outputfd;
|
2000-01-18 06:43:26 +03:00
|
|
|
|
2011-08-12 19:59:20 +04:00
|
|
|
bool quiet;
|
|
|
|
bool showAddress;
|
|
|
|
bool showThreads;
|
2012-01-18 09:11:00 +04:00
|
|
|
bool cleo;
|
2011-08-12 19:59:20 +04:00
|
|
|
u_int stackDepth;
|
2011-08-12 19:59:17 +04:00
|
|
|
int onlyThread;
|
2011-08-12 19:59:20 +04:00
|
|
|
char* output_dir;
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
int mappedLogFile;
|
|
|
|
malloc_log_entry* firstLogEntry;
|
|
|
|
malloc_log_entry* lastLogEntry;
|
|
|
|
|
2000-03-24 00:40:50 +03:00
|
|
|
int stacks;
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
int sfd;
|
2013-04-19 17:54:16 +04:00
|
|
|
Symbol** externalSymbols;
|
|
|
|
Symbol** lastSymbol;
|
2000-03-24 00:40:50 +03:00
|
|
|
int usefulSymbols;
|
|
|
|
int numExternalSymbols;
|
2000-01-18 06:43:26 +03:00
|
|
|
StrSet exclusions;
|
|
|
|
u_long lowestSymbolAddr;
|
|
|
|
u_long highestSymbolAddr;
|
|
|
|
|
|
|
|
LoadMapEntry* loadMap;
|
|
|
|
|
2011-08-12 19:59:17 +04:00
|
|
|
bool collect_last;
|
|
|
|
int collect_start;
|
|
|
|
int collect_end;
|
|
|
|
|
2000-01-18 06:43:26 +03:00
|
|
|
StrSet roots;
|
|
|
|
StrSet includes;
|
|
|
|
|
|
|
|
void usageError();
|
|
|
|
|
|
|
|
void LoadMap();
|
|
|
|
|
2011-05-15 13:47:48 +04:00
|
|
|
void analyze(int thread);
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
void dumpEntryToLog(malloc_log_entry* lep);
|
|
|
|
|
|
|
|
void insertAddress(u_long address, malloc_log_entry* lep);
|
|
|
|
void removeAddress(u_long address, malloc_log_entry* lep);
|
|
|
|
|
|
|
|
void displayStackTrace(FILE* out, malloc_log_entry* lep);
|
|
|
|
|
2013-04-19 17:54:16 +04:00
|
|
|
Symbol ** ExtendSymbols(int num);
|
2000-01-18 06:43:26 +03:00
|
|
|
void ReadSymbols(const char* fileName, u_long aBaseAddress);
|
|
|
|
void ReadSharedLibrarySymbols();
|
|
|
|
void setupSymbols(const char* fileName);
|
|
|
|
Symbol* findSymbol(u_long address);
|
|
|
|
bool excluded(malloc_log_entry* lep);
|
|
|
|
bool included(malloc_log_entry* lep);
|
2013-04-19 17:54:16 +04:00
|
|
|
const char* indexToName(int idx) {return externalSymbols[idx]->name;}
|
2000-01-18 06:43:26 +03:00
|
|
|
|
|
|
|
private:
|
2011-05-15 13:47:48 +04:00
|
|
|
void generateReportHTML(FILE *fp, int *countArray, int count, int thread);
|
2000-01-18 06:43:26 +03:00
|
|
|
int findSymbolIndex(u_long address);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __leaky_h_ */
|