forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.cc
60 lines (44 loc) · 1.36 KB
/
profiler.cc
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
#include "source/common/profiler/profiler.h"
#include <string>
#ifdef PROFILER_AVAILABLE
#include "gperftools/heap-profiler.h"
#include "gperftools/profiler.h"
namespace Envoy {
namespace Profiler {
bool Cpu::profilerEnabled() { return ProfilingIsEnabledForAllThreads(); }
bool Cpu::startProfiler(const std::string& output_path) {
return ProfilerStart(output_path.c_str());
}
void Cpu::stopProfiler() { ProfilerStop(); }
bool Heap::profilerEnabled() {
// determined by PROFILER_AVAILABLE
return true;
}
bool Heap::isProfilerStarted() { return IsHeapProfilerRunning(); }
bool Heap::startProfiler(const std::string& output_file_name_prefix) {
HeapProfilerStart(output_file_name_prefix.c_str());
return true;
}
bool Heap::stopProfiler() {
if (!IsHeapProfilerRunning()) {
return false;
}
HeapProfilerDump("stop and dump");
HeapProfilerStop();
return true;
}
} // namespace Profiler
} // namespace Envoy
#else
namespace Envoy {
namespace Profiler {
bool Cpu::profilerEnabled() { return false; }
bool Cpu::startProfiler(const std::string&) { return false; }
void Cpu::stopProfiler() {}
bool Heap::profilerEnabled() { return false; }
bool Heap::isProfilerStarted() { return false; }
bool Heap::startProfiler(const std::string&) { return false; }
bool Heap::stopProfiler() { return false; }
} // namespace Profiler
} // namespace Envoy
#endif // #ifdef TCMALLOC