Custom track event and build failure

19 views
Skip to first unread message

Jacob Ignatius

unread,
Jun 6, 2025, 4:39:59 AMJun 6
to Perfetto Development - www.perfetto.dev
Hi,

I have created a custom track event, following the instructions on this page: https://perfetto.dev/docs/instrumentation/track-events

So now I am trying to build Perfetto but it keeps failing. I am using a Ubuntu VM and trying to build for an arm64 target. However, it keeps failing because the protoc is incompatible for my host platform.

I tried copying /usr/local/bin/protoc to out/arm64_debug/gcc_like_host/ but now I get a lot of compiler issues:

FAILED: obj/out/arm64_debug/gen/protos/perfetto/common/lite.android_energy_consumer_descriptor.pb.o
../../buildtools/linux64/clang/bin/clang++ --target=aarch64-linux-gnu --sysroot=../../buildtools/debian_sid_arm64-sysroot -MMD -MF obj/out/arm64_debug/gen/protos/perfetto/common/lite.android_energy_consumer_descriptor.pb.o.d -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_ASSERTIONS=1 -D_LIBCPP_DEBUG=0 -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -I../../buildtools/libcxx_config -Igen -fstrict-aliasing -Wformat -g -fPIC -fstack-protector-strong -Werror -fcolor-diagnostics -fdiagnostics-show-template-tree -Wno-c99-designator -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fvisibility=hidden -O0 -funwind-tables -isystem ../../buildtools/protobuf/src -fno-exceptions -fno-rtti -nostdinc++ -isystem../../buildtools/libcxx/include -isystem../../buildtools/libcxxabi/include -std=c++17      -c gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.cc -o obj/out/arm64_debug/gen/protos/perfetto/common/lite.android_energy_consumer_descriptor.pb.o
In file included from gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.cc:4:
gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
   17 | #error This file was generated by an older version of protoc which is
      |  ^
gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
   18 | #error incompatible with your Protocol Buffer headers. Please
      |  ^
gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
   19 | #error regenerate this file with a newer version of protoc.
      |  ^
gen/protos/perfetto/common/android_energy_consumer_descriptor.pb.h:26:10: fatal error: 'google/protobuf/generated_message_table_driven.h' file not found
   26 | #include <google/protobuf/generated_message_table_driven.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
[13/3946] compile gen/protos/perfetto/common/ftrace_descriptor.pb.cc
FAILED: obj/out/arm64_debug/gen/protos/perfetto/common/lite.ftrace_descriptor.pb.o
../../buildtools/linux64/clang/bin/clang++ --target=aarch64-linux-gnu --sysroot=../../buildtools/debian_sid_arm64-sysroot -MMD -MF obj/out/arm64_debug/gen/protos/perfetto/common/lite.ftrace_descriptor.pb.o.d -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_ASSERTIONS=1 -D_LIBCPP_DEBUG=0 -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -I../../buildtools/libcxx_config -Igen -fstrict-aliasing -Wformat -g -fPIC -fstack-protector-strong -Werror -fcolor-diagnostics -fdiagnostics-show-template-tree -Wno-c99-designator -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fvisibility=hidden -O0 -funwind-tables -isystem ../../buildtools/protobuf/src -fno-exceptions -fno-rtti -nostdinc++ -isystem../../buildtools/libcxx/include -isystem../../buildtools/libcxxabi/include -std=c++17      -c gen/protos/perfetto/common/ftrace_descriptor.pb.cc -o obj/out/arm64_debug/gen/protos/perfetto/common/lite.ftrace_descriptor.pb.o
In file included from gen/protos/perfetto/common/ftrace_descriptor.pb.cc:4:

Can you please help? What version of protoc should I be using?

Primiano Tucci

unread,
Jun 6, 2025, 5:21:30 AMJun 6
to Jacob Ignatius, Perfetto Development - www.perfetto.dev
You should really be using the protoc from our codebase, not any protoc compiler you might have in the system.
How are you building everything out of curiosity?
The problem with protobuf is that it's very picky about the fact that the version of the "protoc" binary, and the version of the runtime library must match.

> I tried copying /usr/local/bin/protoc to out/arm64_debug/gcc_like_host/ but now I get a lot of compiler issues:

You cannot do that. You have to use protoc that is built by as part of our build process (in out//arn64_debug/protoc)

Either you have to configure the build to use both protoc and libprotobuf from your system package, or you need to use both from our buildtoolds tree (the one that tools/install-build-deps pulls).
Here what's happening is that you are mixing and matching things.

If you follow our build instructions on https://perfetto.dev/docs/contributing/build-instructions the should do the right thing for you.

If not please give detailed repro steps with the full commandd

--
You received this message because you are subscribed to the Google Groups "Perfetto Development - www.perfetto.dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to perfetto-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/perfetto-dev/299e70d2-53c6-46b3-9033-91ab9e4bb438n%40googlegroups.com.


--
Primiano Tucci
Software Engineer
Google UK Limited

Jacob Ignatius

unread,
Jun 6, 2025, 11:31:13 AMJun 6
to Perfetto Development - www.perfetto.dev
I have abandoned trying to build Perfetto with a custom trace event after discovering that I didn't need it. I can just use GpuCounterEvent.

However, I am having trouble sending this event. I keep getting this error:

gpu_counters_invalid_spec
1816error (analysis)

This is my code:

void GPUMetricsDataSource::sampleGpuMetrics()
{
// check sample is initialised first
if (!sampler)
return;

auto ec = sampler->sample_now();
if (ec)
{
PERFETTO_LOG("Error occurred when sampling: %s", ec.message().c_str());
return;
}

Trace([&](GPUMetricsDataSource::TraceContext ctx)
{
    sendDescriptorPacket(ctx);
    sendCountersPacket(ctx);
});
}

void GPUMetricsDataSource::sendDescriptorPacket(TraceContext &ctx)
{
    auto packet = ctx.NewTracePacket();
    // set timestamp in packet
    packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
    // create gpu counter event
    auto gpuCounterEvent = packet->set_gpu_counter_event();

    auto counterDescriptor = gpuCounterEvent->set_counter_descriptor();
    // add descriptions of all counters
    for (const auto &[id, description]: counterMap)
    {
        auto spec = counterDescriptor->add_specs();
        spec->set_counter_id(id);
        spec->set_description(description);
    }
}

void GPUMetricsDataSource::sendCountersPacket(TraceContext &ctx)
{
    auto packet = ctx.NewTracePacket();
    packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
    auto gpuCounterEvent = packet->set_gpu_counter_event();

    // sample all available counters for GPU
    for (const auto &[id, description]: counterMap)
    {
        // add new counter
        auto counterData = gpuCounterEvent->add_counters();
        counterData->set_counter_id(id);

        hwcpipe::counter_sample sample;
        auto ec = sampler->get_counter_value(id, sample);
        if (ec)
        {
            // error retrieving value
            PERFETTO_LOG("Error getting counter value: %s", ec.message().c_str());
            continue;
        }

        // set the value
        if (sample.type == hwcpipe::counter_sample::type::uint64)
        {
            counterData->set_int_value(static_cast<int64_t>(sample.value.uint64));
        }
        else
        {
            counterData->set_double_value(sample.value.float64);
        }
    }
}

Do you see anything wrong here?

Lalit Maganti

unread,
Jun 6, 2025, 11:35:44 AMJun 6
to Jacob Ignatius, Perfetto Development - www.perfetto.dev
Name is a required file on the counter spec. You appear to be missing that.

You can check [1] for how the events are being parsed to figure out why you might not be seeing information for any problems you have going forward.


Jacob Ignatius

unread,
Jun 6, 2025, 11:39:03 AMJun 6
to Perfetto Development - www.perfetto.dev
Thanks. It's working now.
Reply all
Reply to author
Forward
0 new messages