summaryrefslogtreecommitdiff
path: root/chromium/extensions/common/trace_util.h
blob: 9ccaf349c3895754bf22e08c0fb574f6e9881813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_COMMON_TRACE_UTIL_H_
#define EXTENSIONS_COMMON_TRACE_UTIL_H_

#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "extensions/common/extension_id.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_proto.h"

namespace extensions {

// Helper for logging extension id in go/chrometto traces like so:
//
//     #include "base/trace_event/typed_macros.h"
//     #include "extensions/common/trace_util.h"
//
//     using perfetto::protos::pbzero::ChromeTrackEvent;
//
//     TRACE_EVENT(
//         "extensions", "event name", ...,
//         ChromeTrackEvent::kChromeExtensionId,
//         ExtensionIdForTracing(extension_id),
//         ...);
class ExtensionIdForTracing {
 public:
  explicit ExtensionIdForTracing(const ExtensionId& extension_id)
      : extension_id_(extension_id) {}

  ~ExtensionIdForTracing() = default;

  void WriteIntoTrace(
      perfetto::TracedProto<perfetto::protos::pbzero::ChromeExtensionId> proto)
      const;

 private:
  const ExtensionId extension_id_;
};

}  // namespace extensions

#endif  // EXTENSIONS_COMMON_TRACE_UTIL_H_