• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_TRACE_EVENT_STUB_H_
6 #define BASE_TRACE_EVENT_TRACE_EVENT_STUB_H_
7 
8 #include <stddef.h>
9 
10 #include <cstdint>
11 #include <memory>
12 #include <string>
13 
14 #include "base/base_export.h"
15 #include "base/strings/string_piece.h"
16 #include "base/trace_event/common/trace_event_common.h"
17 #include "base/trace_event/memory_allocator_dump_guid.h"
18 #include "base/values.h"
19 
20 #define TRACE_STR_COPY(str) str
21 #define TRACE_ID_WITH_SCOPE(scope, ...) 0
22 #define TRACE_ID_GLOBAL(id) 0
23 #define TRACE_ID_LOCAL(id) 0
24 
25 namespace trace_event_internal {
26 
27 const unsigned long long kNoId = 0;
28 
29 template <typename... Args>
Ignore(Args &&...args)30 void Ignore(Args&&... args) {}
31 
32 struct IgnoredValue {
33   template <typename... Args>
IgnoredValueIgnoredValue34   IgnoredValue(Args&&... args) {}
35 };
36 
37 }  // namespace trace_event_internal
38 
39 #define INTERNAL_TRACE_IGNORE(...) \
40   (false ? trace_event_internal::Ignore(__VA_ARGS__) : (void)0)
41 
42 #define INTERNAL_TRACE_EVENT_ADD(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
43 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
44 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
45 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(...) \
46   INTERNAL_TRACE_IGNORE(__VA_ARGS__)
47 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(...) \
48   INTERNAL_TRACE_IGNORE(__VA_ARGS__)
49 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMPS(...) \
50   INTERNAL_TRACE_IGNORE(__VA_ARGS__)
51 
52 // Defined in application_state_proto_android.h
53 #define TRACE_APPLICATION_STATE(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
54 
55 #define TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION \
56   trace_event_internal::IgnoredValue
57 
58 #define TRACE_ID_MANGLE(val) (val)
59 
60 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(cat) INTERNAL_TRACE_IGNORE(cat);
61 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() false
62 
63 #define TRACE_EVENT_API_CURRENT_THREAD_ID 0
64 
65 // Typed macros. For these, we have to erase the extra args entirely, as they
66 // may include a lambda that refers to protozero message types (which aren't
67 // available in the stub). This may trigger "unused variable" errors at the
68 // callsite, which have to be addressed at the callsite (e.g. via
69 // [[maybe_unused]]).
70 #define TRACE_EVENT_BEGIN(category, name, ...) \
71   INTERNAL_TRACE_IGNORE(category, name)
72 #define TRACE_EVENT_END(category, ...) INTERNAL_TRACE_IGNORE(category)
73 #define TRACE_EVENT(category, name, ...) INTERNAL_TRACE_IGNORE(category, name)
74 #define TRACE_EVENT_INSTANT(category, name, ...) \
75   INTERNAL_TRACE_IGNORE(category, name)
76 #define PERFETTO_INTERNAL_ADD_EMPTY_EVENT() INTERNAL_TRACE_IGNORE()
77 
78 namespace base {
79 namespace trace_event {
80 
81 class BASE_EXPORT ConvertableToTraceFormat {
82  public:
83   ConvertableToTraceFormat() = default;
84   ConvertableToTraceFormat(const ConvertableToTraceFormat&) = delete;
85   ConvertableToTraceFormat& operator=(const ConvertableToTraceFormat&) = delete;
86   virtual ~ConvertableToTraceFormat();
87 
88   // Append the class info to the provided |out| string. The appended
89   // data must be a valid JSON object. Strings must be properly quoted, and
90   // escaped. There is no processing applied to the content after it is
91   // appended.
92   virtual void AppendAsTraceFormat(std::string* out) const = 0;
93 };
94 
95 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat {
96  public:
97   explicit TracedValue(size_t capacity = 0) {}
98 
EndDictionary()99   void EndDictionary() {}
EndArray()100   void EndArray() {}
101 
SetInteger(const char * name,int value)102   void SetInteger(const char* name, int value) {}
SetDouble(const char * name,double value)103   void SetDouble(const char* name, double value) {}
SetBoolean(const char * name,bool value)104   void SetBoolean(const char* name, bool value) {}
SetString(const char * name,base::StringPiece value)105   void SetString(const char* name, base::StringPiece value) {}
SetValue(const char * name,TracedValue * value)106   void SetValue(const char* name, TracedValue* value) {}
BeginDictionary(const char * name)107   void BeginDictionary(const char* name) {}
BeginArray(const char * name)108   void BeginArray(const char* name) {}
109 
SetIntegerWithCopiedName(base::StringPiece name,int value)110   void SetIntegerWithCopiedName(base::StringPiece name, int value) {}
SetDoubleWithCopiedName(base::StringPiece name,double value)111   void SetDoubleWithCopiedName(base::StringPiece name, double value) {}
SetBooleanWithCopiedName(base::StringPiece name,bool value)112   void SetBooleanWithCopiedName(base::StringPiece name, bool value) {}
SetStringWithCopiedName(base::StringPiece name,base::StringPiece value)113   void SetStringWithCopiedName(base::StringPiece name,
114                                base::StringPiece value) {}
SetValueWithCopiedName(base::StringPiece name,TracedValue * value)115   void SetValueWithCopiedName(base::StringPiece name, TracedValue* value) {}
BeginDictionaryWithCopiedName(base::StringPiece name)116   void BeginDictionaryWithCopiedName(base::StringPiece name) {}
BeginArrayWithCopiedName(base::StringPiece name)117   void BeginArrayWithCopiedName(base::StringPiece name) {}
118 
AppendInteger(int)119   void AppendInteger(int) {}
AppendDouble(double)120   void AppendDouble(double) {}
AppendBoolean(bool)121   void AppendBoolean(bool) {}
AppendString(base::StringPiece)122   void AppendString(base::StringPiece) {}
BeginArray()123   void BeginArray() {}
BeginDictionary()124   void BeginDictionary() {}
125 
126   void AppendAsTraceFormat(std::string* out) const override;
127 };
128 
129 class BASE_EXPORT TracedValueJSON : public TracedValue {
130  public:
TracedValue(capacity)131   explicit TracedValueJSON(size_t capacity = 0) : TracedValue(capacity) {}
132 
ToBaseValue()133   std::unique_ptr<base::Value> ToBaseValue() const { return nullptr; }
ToJSON()134   std::string ToJSON() const { return ""; }
ToFormattedJSON()135   std::string ToFormattedJSON() const { return ""; }
136 };
137 
138 struct MemoryDumpArgs;
139 class ProcessMemoryDump;
140 
141 class BASE_EXPORT MemoryDumpProvider {
142  public:
143   MemoryDumpProvider(const MemoryDumpProvider&) = delete;
144   MemoryDumpProvider& operator=(const MemoryDumpProvider&) = delete;
145   virtual ~MemoryDumpProvider();
146 
147   virtual bool OnMemoryDump(const MemoryDumpArgs& args,
148                             ProcessMemoryDump* pmd) = 0;
149 
150  protected:
151   MemoryDumpProvider() = default;
152 };
153 
154 class BASE_EXPORT MemoryDumpManager {
155  public:
156   static constexpr const char* const kTraceCategory =
157       TRACE_DISABLED_BY_DEFAULT("memory-infra");
158 };
159 
160 }  // namespace trace_event
161 }  // namespace base
162 
163 // Stub implementation for
164 // perfetto::StaticString/ThreadTrack/TracedValue/TracedDictionary/TracedArray.
165 namespace perfetto {
166 
167 class TracedArray;
168 class TracedDictionary;
169 class EventContext;
170 
171 class StaticString {
172  public:
173   template <typename T>
StaticString(T)174   StaticString(T) {}
175 };
176 
177 class DynamicString {
178  public:
179   template <typename T>
DynamicString(T)180   explicit DynamicString(T) {}
181 };
182 
183 class TracedValue {
184  public:
WriteInt64(int64_t)185   void WriteInt64(int64_t) && {}
WriteUInt64(uint64_t)186   void WriteUInt64(uint64_t) && {}
WriteDouble(double)187   void WriteDouble(double) && {}
WriteBoolean(bool)188   void WriteBoolean(bool) && {}
WriteString(const char *)189   void WriteString(const char*) && {}
WriteString(const char *,size_t)190   void WriteString(const char*, size_t) && {}
WriteString(const std::string &)191   void WriteString(const std::string&) && {}
WritePointer(const void *)192   void WritePointer(const void*) && {}
193 
194   TracedDictionary WriteDictionary() &&;
195   TracedArray WriteArray() &&;
196 };
197 
198 class TracedDictionary {
199  public:
AddItem(StaticString)200   TracedValue AddItem(StaticString) { return TracedValue(); }
AddItem(DynamicString)201   TracedValue AddItem(DynamicString) { return TracedValue(); }
202 
203   template <typename T>
Add(StaticString,T &&)204   void Add(StaticString, T&&) {}
205   template <typename T>
Add(DynamicString,T &&)206   void Add(DynamicString, T&&) {}
207 
208   TracedDictionary AddDictionary(StaticString);
209   TracedDictionary AddDictionary(DynamicString);
210   TracedArray AddArray(StaticString);
211   TracedArray AddArray(DynamicString);
212 };
213 
214 class TracedArray {
215  public:
AppendItem()216   TracedValue AppendItem() { return TracedValue(); }
217 
218   template <typename T>
Append(T &&)219   void Append(T&&) {}
220 
221   TracedDictionary AppendDictionary();
222   TracedArray AppendArray();
223 };
224 
225 template <class T>
WriteIntoTracedValue(TracedValue,T &&)226 void WriteIntoTracedValue(TracedValue, T&&) {}
227 
228 namespace protos::pbzero {
229 namespace SequenceManagerTask {
230 
231 enum class QueueName {
232   UNKNOWN_TQ = 0,
233   DEFAULT_TQ = 1,
234   TASK_ENVIRONMENT_DEFAULT_TQ = 2,
235   TEST2_TQ = 3,
236   TEST_TQ = 4,
237 };
QueueName_Name(QueueName value)238 inline const char* QueueName_Name(QueueName value) {
239   switch (value) {
240     case QueueName::UNKNOWN_TQ:
241       return "UNKNOWN_TQ";
242     case QueueName::DEFAULT_TQ:
243       return "DEFAULT_TQ";
244     case QueueName::TASK_ENVIRONMENT_DEFAULT_TQ:
245       return "TASK_ENVIRONMENT_DEFAULT_TQ";
246     case QueueName::TEST2_TQ:
247       return "TEST2_TQ";
248     case QueueName::TEST_TQ:
249       return "TEST_TQ";
250   }
251 }
252 
253 }  // namespace SequenceManagerTask
254 
255 namespace ChromeProcessDescriptor {
256 
257 enum ProcessType {};
258 
259 }  // namespace ChromeProcessDescriptor
260 
261 }  // namespace protos::pbzero
262 }  // namespace perfetto
263 
264 #endif  // BASE_TRACE_EVENT_TRACE_EVENT_STUB_H_
265