• Sami Kyostila's avatar
    trace_event: Add support for interned data in typed events · 1144484f
    Sami Kyostila authored
    This patch adds support for interned data in typed trace points. This
    helps to reduce trace size for frequently repeated data.
    
    As an example, an interning index for base::Location could be defined as
    follows:
    
    struct InternedLocationIndex
        : public perfetto::TrackEventInternedDataIndex<
              InternedLocationIndex,
              perfetto::protos::pbzero::
                  InternedData::kSourceLocationsFieldNumber,
              Location> {
      static void Add(perfetto::protos::pbzero::InternedData* interned_data,
                      size_t iid,
                      const Location& location) {
        auto* loc = interned_data->add_source_locations();
        loc->set_file_name(location.file_name());
        loc->set_function_name(location.function_name());
        loc->set_line_number(location.line_number());
      }
    };
    
    A corresponding typed trace point using the index could look like this:
    
      TRACE_EVENT("cat", "Name", [](perfetto::EventContext ctx) {
        auto* log = ctx.event()->set_log_message();
        size_t iid = InternedLocationIndex::Get(&ctx, FROM_HERE);
        log->set_body_iid(iid);
      }
    
    Bug: b/156727531
    Change-Id: I5a78784be688071f7373ac1655b1ce74428f7b0f
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410117
    Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
    Commit-Queue: Wez <wez@chromium.org>
    Reviewed-by: default avatarWez <wez@chromium.org>
    Reviewed-by: default avatarStephen Nusko <nuskos@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#808484}
    1144484f
BUILD.gn 147 KB