Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/source/common/profiler/profiler.cc
Line
Count
Source (jump to first uncovered line)
1
#include "source/common/profiler/profiler.h"
2
3
#include <string>
4
5
#ifdef PROFILER_AVAILABLE
6
7
#include "gperftools/heap-profiler.h"
8
#include "gperftools/profiler.h"
9
10
namespace Envoy {
11
namespace Profiler {
12
13
bool Cpu::profilerEnabled() { return ProfilingIsEnabledForAllThreads(); }
14
15
bool Cpu::startProfiler(const std::string& output_path) {
16
  return ProfilerStart(output_path.c_str());
17
}
18
19
void Cpu::stopProfiler() { ProfilerStop(); }
20
21
bool Heap::profilerEnabled() {
22
  // determined by PROFILER_AVAILABLE
23
  return true;
24
}
25
26
bool Heap::isProfilerStarted() { return IsHeapProfilerRunning(); }
27
bool Heap::startProfiler(const std::string& output_file_name_prefix) {
28
  HeapProfilerStart(output_file_name_prefix.c_str());
29
  return true;
30
}
31
32
bool Heap::stopProfiler() {
33
  if (!IsHeapProfilerRunning()) {
34
    return false;
35
  }
36
  HeapProfilerDump("stop and dump");
37
  HeapProfilerStop();
38
  return true;
39
}
40
41
} // namespace Profiler
42
} // namespace Envoy
43
44
#else
45
46
namespace Envoy {
47
namespace Profiler {
48
49
0
bool Cpu::profilerEnabled() { return false; }
50
0
bool Cpu::startProfiler(const std::string&) { return false; }
51
0
void Cpu::stopProfiler() {}
52
53
0
bool Heap::profilerEnabled() { return false; }
54
0
bool Heap::isProfilerStarted() { return false; }
55
0
bool Heap::startProfiler(const std::string&) { return false; }
56
0
bool Heap::stopProfiler() { return false; }
57
58
} // namespace Profiler
59
} // namespace Envoy
60
61
#endif // #ifdef PROFILER_AVAILABLE
62
63
#ifdef TCMALLOC
64
65
#include "tcmalloc/malloc_extension.h"
66
#include "tcmalloc/profile_marshaler.h"
67
68
namespace Envoy {
69
namespace Profiler {
70
71
absl::StatusOr<std::string> TcmallocProfiler::tcmallocHeapProfile() {
72
  auto profile = tcmalloc::MallocExtension::SnapshotCurrent(tcmalloc::ProfileType::kHeap);
73
  return tcmalloc::Marshal(profile);
74
}
75
76
} // namespace Profiler
77
} // namespace Envoy
78
79
#else
80
81
namespace Envoy {
82
namespace Profiler {
83
84
0
absl::StatusOr<std::string> TcmallocProfiler::tcmallocHeapProfile() {
85
0
  return absl::Status(absl::StatusCode::kUnimplemented,
86
0
                      "Heap profile is not implemented in current build");
87
0
}
88
89
} // namespace Profiler
90
} // namespace Envoy
91
92
#endif // #ifdef TCMALLOC