trace_util.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef EXTENSIONS_COMMON_TRACE_UTIL_H_
  5. #define EXTENSIONS_COMMON_TRACE_UTIL_H_
  6. #include "base/tracing/protos/chrome_track_event.pbzero.h"
  7. #include "extensions/common/extension_id.h"
  8. #include "third_party/perfetto/include/perfetto/tracing/traced_proto.h"
  9. namespace extensions {
  10. // Helper for logging extension id in go/chrometto traces like so:
  11. //
  12. // #include "base/trace_event/typed_macros.h"
  13. // #include "extensions/common/trace_util.h"
  14. //
  15. // using perfetto::protos::pbzero::ChromeTrackEvent;
  16. //
  17. // TRACE_EVENT(
  18. // "extensions", "event name", ...,
  19. // ChromeTrackEvent::kChromeExtensionId,
  20. // ExtensionIdForTracing(extension_id),
  21. // ...);
  22. class ExtensionIdForTracing {
  23. public:
  24. explicit ExtensionIdForTracing(const ExtensionId& extension_id)
  25. : extension_id_(extension_id) {}
  26. ~ExtensionIdForTracing() = default;
  27. void WriteIntoTrace(
  28. perfetto::TracedProto<perfetto::protos::pbzero::ChromeExtensionId> proto)
  29. const;
  30. private:
  31. const ExtensionId extension_id_;
  32. };
  33. } // namespace extensions
  34. #endif // EXTENSIONS_COMMON_TRACE_UTIL_H_