• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TRACE_EVENT_NAMED_TRIGGER_H_
6 #define BASE_TRACE_EVENT_NAMED_TRIGGER_H_
7 
8 #include <stdint.h>
9 
10 #include <optional>
11 #include <string>
12 
13 #include "base/base_export.h"
14 #include "base/trace_event/base_tracing.h"
15 
16 namespace base::trace_event {
17 
18 inline constexpr char kStartupTracingTriggerName[] = "startup";
19 
20 // Notifies that a manual trigger event has occurred. Returns true if the
21 // trigger caused a scenario to either begin recording or finalize the trace
22 // depending on the config, or false if the trigger had no effect. If the
23 // trigger specified isn't active in the config, this will do nothing.
24 BASE_EXPORT bool EmitNamedTrigger(const std::string& trigger_name,
25                                   std::optional<int32_t> value = std::nullopt);
26 
27 class NamedTriggerManager {
28  public:
29   virtual bool DoEmitNamedTrigger(const std::string& trigger_name,
30                                   std::optional<int32_t> value) = 0;
31 
32  protected:
33   // Sets the instance returns by GetInstance() globally to |manager|.
34   BASE_EXPORT static void SetInstance(NamedTriggerManager* manager);
35 };
36 
37 // Returns a flow id that connects to a background tracing trigger.
38 BASE_EXPORT uint64_t TriggerFlowId(const std::string_view& name,
39                                    std::optional<int32_t> value = std::nullopt);
40 
41 // Returns a perfetto flow that connects to a background tracing trigger.
42 BASE_EXPORT perfetto::Flow TriggerFlow(
43     const std::string_view& name,
44     std::optional<int32_t> value = std::nullopt);
45 
46 }  // namespace base::trace_event
47 
48 #endif  // BASE_TRACE_EVENT_NAMED_TRIGGER_H_
49