-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitchCXX
93 lines (70 loc) · 2.27 KB
/
BitchCXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
发件人: Sun,Yixing
发送时间: 2013年11月7日 19:31
收件人: Zhang,Qida
主题: 贱器
class HeapProfile
{
public:
HeapProfile()
{
_stop = false;
_pid = getpid();
pthread_create(&_tid, NULL, monitor, NULL);
}
static void* monitor(void*)
{
DIR *dir;
struct dirent *dent;
char buf[128];
pthread_detach(pthread_self());
BIGPIPE_LOG_FATAL("monitor running %d", _pid);
while (!_stop) {
sleep(5);
dir = opendir("/tmp");
while ((dent = readdir(dir))) {
sprintf(buf, "heap_profile.start.%d", _pid);
if (strcmp(buf, dent->d_name) == 0) {
BIGPIPE_LOG_FATAL("heap profile start");
HeapProfilerStart("thomas");
sprintf(buf, "/tmp/heap_profile.start.%d", _pid);
unlink(buf);
break;
}
sprintf(buf, "heap_profile.dump.%d", _pid);
if (strcmp(buf, dent->d_name) == 0) {
BIGPIPE_LOG_FATAL("heap profile dump");
HeapProfilerDump("heap_file");
sprintf(buf, "/tmp/heap_profile.dump.%d", _pid);
unlink(buf);
break;
}
sprintf(buf, "heap_profile.stop.%d", _pid);
if (strcmp(buf, dent->d_name) == 0) {
BIGPIPE_LOG_FATAL("heap profile stop");
HeapProfilerStop();
sprintf(buf, "/tmp/heap_profile.stop.%d", _pid);
unlink(buf);
_stop = true;
break;
}
}
closedir(dir);
}
return NULL;
}
private:
static bool _stop;
pthread_t _tid;
static pid_t _pid;
};
bool HeapProfile::_stop;
pid_t HeapProfile::_pid;
然后在你需要的地方放个 HeapProfile 变量
libpath=/path/to/tcmalloc
LDFLAGS 加上 -L$libpath/lib -ltcmalloc
CPPFLAGS 加上 -I$libpath/include
启动进程
LD_PRELOAD=$libpath/lib/libtcmalloc.so ./your_bin
启动: touch /tmp/heap_profile.start.17281
DUMP: touch /tmp/heap_profile.dump.17281
////问题解决之后,要工整地抽象成工具