Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@ if (enable_perfetto_trace_processor_linenoise) {
# Only used by src/profiling in standalone and android builds.
if (enable_perfetto_heapprofd || enable_perfetto_traced_perf) {
group("libunwindstack") {
public_configs = [ "//buildtools:libunwindstack_config" ]
public_deps = [ "//buildtools:libunwindstack" ]
if (build_with_chromium && is_android) {
public_configs = [ "//third_party/libunwindstack:libunwindstack_config" ]
public_deps = [ "//third_party/libunwindstack" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is likely to cause problems in the rolls.
libunwind stack is subjected to breaking changes every now and then. when it happens, we have to catch up with upstream (Android). But this means whenver we do, the chromium roll will fail.

It's the biggest worry I have about this PR. This is going to doom us to get stuck on the chromium rolls.
I think the best ay forward would be to create an indirection layer in the unwinder, and allow chrome to plug in its unwinder (you can use your own copy of libunwindstack, and that's better because there is no direct coupling)

This dependency is going to be a time-bomb unfortunately

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've noticed that libunwindstack in Chrome is also broken (it does not successfully strip the pointer-authentication bits). Is there an underlying reason why libunwindstack is used for Perfetto instead of the canonical LLVM libunwind?

} else {
public_configs = [ "//buildtools:libunwindstack_config" ]
public_deps = [ "//buildtools:libunwindstack" ]
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gn/perfetto.gni
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ declare_args() {
# but is built on Linux as well for test/compiler coverage.
# On Android, it requires API level 26 due to libunwindstack.
enable_perfetto_heapprofd =
perfetto_build_with_android ||
perfetto_build_with_android || (build_with_chromium && is_android) ||
(perfetto_build_standalone && is_clang &&
(is_linux || (is_android && android_api_level >= 26)))

Expand Down
1 change: 1 addition & 0 deletions src/profiling/common/proc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sys/types.h>

#include <cinttypes>
#include <cstdlib>
#include <optional>
#include <set>
#include <vector>
Expand Down
8 changes: 8 additions & 0 deletions src/profiling/common/profiler_guardrails.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
#include <algorithm>
#include <optional>

#include "perfetto/base/build_config.h"
#include "perfetto/ext/base/file_utils.h"
#include "perfetto/ext/base/scoped_file.h"

#if PERFETTO_BUILDFLAG(PERFETTO_WATCHDOG)
#include "perfetto/ext/base/watchdog_posix.h"
#endif

namespace perfetto {
namespace profiling {
Expand All @@ -36,13 +40,17 @@ std::optional<uint64_t> GetCputimeSecForCurrentProcess(
base::ScopedFile stat_fd) {
if (!stat_fd)
return std::nullopt;
#if PERFETTO_BUILDFLAG(PERFETTO_WATCHDOG)
base::ProcStat stat;
if (!ReadProcStat(stat_fd.get(), &stat)) {
PERFETTO_ELOG("Failed to read stat file to enforce guardrails.");
return std::nullopt;
}
return (stat.utime + stat.stime) /
static_cast<unsigned long>(sysconf(_SC_CLK_TCK));
#else
return std::nullopt;
#endif
}

ProfilerMemoryGuardrails::ProfilerMemoryGuardrails()
Expand Down
64 changes: 35 additions & 29 deletions src/profiling/memory/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ shared_library("heapprofd_api_noop") {

# This target does absolutely nothing, so we do not want to depend on
# liblog.
configs -= [ "//gn/standalone:android_liblog" ] # nogncheck
if (perfetto_build_standalone) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(here and below) well also `|| build_with_android) no? (or !build_with_chromium to be more conservative)

configs -= [ "//gn/standalone:android_liblog" ] # nogncheck
}
sources = [ "client_api_noop.cc" ]
}

shared_library("heapprofd_client_api") {
configs -= [ "//gn/standalone:android_liblog" ] # nogncheck
if (perfetto_build_standalone) {
configs -= [ "//gn/standalone:android_liblog" ] # nogncheck
}
if (perfetto_build_with_android) {
cflags = [ "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG" ]
} else {
Expand Down Expand Up @@ -352,33 +356,35 @@ perfetto_unittest_source_set("unittests") {
}
}

source_set("end_to_end_tests") {
testonly = true
deps = [
":client",
":daemon",
":wire_protocol",
"../../../gn:default_deps",
"../../../gn:gtest_and_gmock",
"../../../gn:libunwindstack",
"../../../protos/perfetto/config/profiling:cpp",
"../../../protos/perfetto/trace/interned_data:cpp",
"../../../protos/perfetto/trace/profiling:cpp",
"../../../test:integrationtest_initializer",
"../../../test:test_helper",
"../../base",
"../../base:test_support",
"../../trace_processor:lib",
"../../tracing/test:test_support",
]
sources = [
"heapprofd_end_to_end_test.cc",
"heapprofd_producer_integrationtest.cc",
]
if (perfetto_build_with_android) {
deps += [ ":heapprofd_client_api" ]
} else {
deps += [ ":heapprofd_standalone_client" ]
if (enable_perfetto_integration_tests) {
source_set("end_to_end_tests") {
testonly = true
deps = [
":client",
":daemon",
":wire_protocol",
"../../../gn:default_deps",
"../../../gn:gtest_and_gmock",
"../../../gn:libunwindstack",
"../../../protos/perfetto/config/profiling:cpp",
"../../../protos/perfetto/trace/interned_data:cpp",
"../../../protos/perfetto/trace/profiling:cpp",
"../../../test:integrationtest_initializer",
"../../../test:test_helper",
"../../base",
"../../base:test_support",
"../../trace_processor:lib",
"../../tracing/test:test_support",
]
sources = [
"heapprofd_end_to_end_test.cc",
"heapprofd_producer_integrationtest.cc",
]
if (perfetto_build_with_android) {
deps += [ ":heapprofd_client_api" ]
} else {
deps += [ ":heapprofd_standalone_client" ]
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/profiling/memory/unwinding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ constexpr size_t kMaxAllocRecordArenaSize = 2 * kRecordBatchSize;
#pragma GCC diagnostic ignored "-Wglobal-constructors"
#pragma GCC diagnostic ignored "-Wexit-time-destructors"
static std::vector<std::string> kSkipMaps{"heapprofd_client.so",
"heapprofd_client_api.so"};
"heapprofd_client_api.so",
"libheapprofd_standalone_client.so"};
#pragma GCC diagnostic pop

size_t GetRegsSize(unwindstack::Regs* regs) {
Expand Down
2 changes: 1 addition & 1 deletion src/profiling/memory/wire_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ constexpr size_t kMaxRegisterDataSize =
sizeof(uint64_t) * unwindstack::ARM64_REG_LAST,
sizeof(uint32_t) * unwindstack::X86_REG_LAST,
sizeof(uint64_t) * unwindstack::X86_64_REG_LAST,
sizeof(uint64_t) * unwindstack::RISCV64_REG_COUNT});
sizeof(uint64_t) * unwindstack::RISCV64_REG_MAX});
Copy link
Member

@primiano primiano Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is preceisely the problem I was describing. You are effetively trying to undo https://android-review.git.corp.google.com/c/platform/external/perfetto/+/2918494 likely becuase your libunwindstack version is behind upstream.

Unfortunately this creates a upstream XOR your_version situation that doesn't work for us

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, Chrome's libunwindstack is mostly only used for Perfetto so I think it's fine to align the two versions.


// Types needed for the wire format used for communication between the client
// and heapprofd. The basic format of a record sent by the client is
Expand Down
66 changes: 34 additions & 32 deletions src/traced/probes/packages_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,39 @@ source_set("packages_list_parser") {
]
}

source_set("packages_list") {
public_deps = [ "../../../tracing/core" ]
deps = [
":packages_list_parser",
"..:data_source",
"../../../../gn:default_deps",
"../../../../include/perfetto/ext/traced",
"../../../../protos/perfetto/common:zero",
"../../../../protos/perfetto/config/android:zero",
"../../../../protos/perfetto/trace:zero",
"../../../../protos/perfetto/trace/android:zero",
"../../../base",
"../common",
]
sources = [
"packages_list_data_source.cc",
"packages_list_data_source.h",
]
}
if (enable_perfetto_traced_probes) {
source_set("packages_list") {
public_deps = [ "../../../tracing/core" ]
deps = [
":packages_list_parser",
"..:data_source",
"../../../../gn:default_deps",
"../../../../include/perfetto/ext/traced",
"../../../../protos/perfetto/common:zero",
"../../../../protos/perfetto/config/android:zero",
"../../../../protos/perfetto/trace:zero",
"../../../../protos/perfetto/trace/android:zero",
"../../../base",
"../common",
]
sources = [
"packages_list_data_source.cc",
"packages_list_data_source.h",
]
}

perfetto_unittest_source_set("unittests") {
testonly = true
deps = [
":packages_list",
":packages_list_parser",
"../../../../gn:default_deps",
"../../../../gn:gtest_and_gmock",
"../../../../protos/perfetto/trace/android:cpp",
"../../../../protos/perfetto/trace/android:zero",
"../../../../src/base:test_support",
"../../../../src/tracing/test:test_support",
]
sources = [ "packages_list_unittest.cc" ]
perfetto_unittest_source_set("unittests") {
testonly = true
deps = [
":packages_list",
":packages_list_parser",
"../../../../gn:default_deps",
"../../../../gn:gtest_and_gmock",
"../../../../protos/perfetto/trace/android:cpp",
"../../../../protos/perfetto/trace/android:zero",
"../../../../src/base:test_support",
"../../../../src/tracing/test:test_support",
]
sources = [ "packages_list_unittest.cc" ]
}
}
Loading