google / perfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)
https://www.perfetto.dev
Apache License 2.0
2.84k stars 356 forks source link

How to build `libheadprofd_glibc_preload.so` for native heapprofd (on Linux) still? #186

Closed q-p closed 2 years ago

q-p commented 3 years ago

Edit: All this is based on v20.1 of the SDK.

The documentation at https://perfetto.dev/docs/data-sources/native-heap-profiler#-non-android-linux-support indicates steps to get a heap profile on native (non-Android) Linux, but following the instructions, I was never able to get it to build the mentioned libheapprofd_glibc_preload.so library. It builds the other stuff (tools, sdk, etc.) as expected (after fixing a few minor build problems)*.

I've been building (on x86_64 Linux with gcc 8.2) with is_clang = false and both default and is_debug = false, but neither produced that library.

*The problems I ran into were:

diff --git a/src/trace_processor/importers/proto/flamegraph_construction_algorithms.cc b/src/trace_processor/importers/proto/flamegraph_construction_algorithms.cc
index db0e924..97643d3 100644
--- a/src/trace_processor/importers/proto/flamegraph_construction_algorithms.cc
+++ b/src/trace_processor/importers/proto/flamegraph_construction_algorithms.cc
@@ -391,7 +391,7 @@ BuildNativeCallStackSamplingFlamegraph(
   for (const auto& tc : time_constraints) {
     if (!(tc.op == FilterOp::kGt || tc.op == FilterOp::kLt ||
           tc.op == FilterOp::kGe || tc.op == FilterOp::kLe)) {
-      PERFETTO_FATAL("Filter operation %d not permitted for perf.", tc.op);
+      PERFETTO_FATAL("Filter operation not permitted for perf.");
     }

as tc.op wasn't printable using %d according to gcc 8.2's printf warning.

diff --git a/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc b/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
index 510f776..8a75df2 100644
--- a/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
+++ b/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
@@ -49,7 +49,7 @@ void BenchmarkArgs(benchmark::internal::Benchmark* b) {
 class BenchmarkCursor : public sqlite3_vtab_cursor {
  public:
   explicit BenchmarkCursor(size_t num_cols, size_t batch_size)
-      : num_cols_(num_cols), batch_size_(batch_size), rnd_engine_(kRandomSeed) {
+      : num_cols_(num_cols), batch_size_(batch_size), rnd_engine_(1) {
     column_buffer_.resize(num_cols);
     for (auto& col : column_buffer_)
       col.resize(batch_size);

kRandomSeed (from some anonymous namespace iirc) wasn't found during linking, so I just hardcoded a number.

diff --git a/src/traced/probes/ftrace/proto_translation_table_unittest.cc b/src/traced/probes/ftrace/proto_translation_table_unittest.cc
index 0210f71..4f2b98a 100644
--- a/src/traced/probes/ftrace/proto_translation_table_unittest.cc
+++ b/src/traced/probes/ftrace/proto_translation_table_unittest.cc
@@ -371,7 +371,7 @@ TEST(TranslationTableTest, Getters) {
   std::vector<Event> events;

   {
-    Event event;
+    Event event{};
     event.name = "foo";
     event.group = "group_one";
     event.ftrace_event_id = 1;
@@ -379,7 +379,7 @@ TEST(TranslationTableTest, Getters) {
   }

   {
-    Event event;
+    Event event{};
     event.name = "bar";
     event.group = "group_one";
     event.ftrace_event_id = 2;
@@ -387,7 +387,7 @@ TEST(TranslationTableTest, Getters) {
   }

   {
-    Event event;
+    Event event{};
     event.name = "baz";
     event.group = "group_two";
     event.ftrace_event_id = 100;

as event produced an "using initialized fields" warning.

primiano commented 3 years ago

tc.op

Ah, fun. I just saw this the other day and fixed in r.android.com/1853531

kRandomSeed

This is weird I can't repro this.

Which compiler are you using? Maybe it's too old. We build continuously with gcc-7 in ci.perfetto.dev

Anyhow, mind sending a patch if you can figure out a fix? See https://perfetto.dev/docs/contributing/getting-started

Thanks, Primiano

q-p commented 3 years ago

kRandomSeed

This is weird I can't repro this.

It seems that that (g++ 8.2) version of libstdc++ takes the seed by reference thereby resulting in the linker error as it is never defined but only declared (pre C++17).

The following fixes it for me:

diff --git a/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc b/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
index 510f77687..85cb0278c 100644
--- a/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
+++ b/src/trace_processor/sqlite/sqlite_vtable_benchmark.cc
@@ -71,6 +71,7 @@ class BenchmarkCursor : public sqlite3_vtab_cursor {

   std::minstd_rand0 rnd_engine_;
 };
+constexpr uint32_t BenchmarkCursor::kRandomSeed;

 void BenchmarkCursor::RandomFill() {
   for (size_t col = 0; col < num_cols_; col++) {
LalitMaganti commented 2 years ago

Given this is on an old compiler version + old SDK, closing. Please reopen if this still happens today.