trace_event_stub.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Copyright 2020 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 BASE_TRACE_EVENT_TRACE_EVENT_STUB_H_
  5. #define BASE_TRACE_EVENT_TRACE_EVENT_STUB_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include "base/base_export.h"
  9. #include "base/macros.h"
  10. #include "base/strings/string_piece.h"
  11. #include "base/trace_event/common/trace_event_common.h"
  12. #include "base/trace_event/memory_allocator_dump_guid.h"
  13. #include "base/values.h"
  14. #define TRACE_STR_COPY(str) str
  15. #define TRACE_ID_WITH_SCOPE(scope, ...) 0
  16. #define TRACE_ID_GLOBAL(id) 0
  17. #define TRACE_ID_LOCAL(id) 0
  18. namespace trace_event_internal {
  19. const unsigned long long kNoId = 0;
  20. template <typename... Args>
  21. void Ignore(Args&&... args) {}
  22. struct IgnoredValue {
  23. template <typename... Args>
  24. IgnoredValue(Args&&... args) {}
  25. };
  26. } // namespace trace_event_internal
  27. #define INTERNAL_TRACE_IGNORE(...) \
  28. (false ? trace_event_internal::Ignore(__VA_ARGS__) : (void)0)
  29. #define INTERNAL_TRACE_EVENT_ADD(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  30. #define INTERNAL_TRACE_EVENT_ADD_SCOPED(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  31. #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  32. #define INTERNAL_TRACE_TASK_EXECUTION(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  33. #define INTERNAL_TRACE_LOG_MESSAGE(...) INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  34. #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(...) \
  35. INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  36. #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(...) \
  37. INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  38. #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMPS(...) \
  39. INTERNAL_TRACE_IGNORE(__VA_ARGS__)
  40. #define TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION \
  41. trace_event_internal::IgnoredValue
  42. #define TRACE_ID_MANGLE(val) (val)
  43. #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(cat) INTERNAL_TRACE_IGNORE(cat);
  44. #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() false
  45. #define TRACE_EVENT_API_CURRENT_THREAD_ID 0
  46. // Typed macros. For these, we have to erase the extra args entirely, as they
  47. // may include a lambda that refers to protozero message types (which aren't
  48. // available in the stub). This may trigger "unused variable" errors at the
  49. // callsite, which have to be addressed at the callsite (e.g. via
  50. // ignore_result()).
  51. #define TRACE_EVENT_BEGIN(category, name, ...) \
  52. INTERNAL_TRACE_IGNORE(category, name)
  53. #define TRACE_EVENT_END(category, ...) INTERNAL_TRACE_IGNORE(category)
  54. #define TRACE_EVENT(category, name, ...) INTERNAL_TRACE_IGNORE(category, name)
  55. #define TRACE_EVENT_INSTANT(category, name, scope, ...) \
  56. INTERNAL_TRACE_IGNORE(category, name, scope)
  57. namespace base {
  58. namespace trace_event {
  59. class BASE_EXPORT ConvertableToTraceFormat {
  60. public:
  61. ConvertableToTraceFormat() = default;
  62. virtual ~ConvertableToTraceFormat();
  63. // Append the class info to the provided |out| string. The appended
  64. // data must be a valid JSON object. Strings must be properly quoted, and
  65. // escaped. There is no processing applied to the content after it is
  66. // appended.
  67. virtual void AppendAsTraceFormat(std::string* out) const = 0;
  68. private:
  69. DISALLOW_COPY_AND_ASSIGN(ConvertableToTraceFormat);
  70. };
  71. class BASE_EXPORT TracedValue : public ConvertableToTraceFormat {
  72. public:
  73. explicit TracedValue(size_t capacity = 0) {}
  74. void EndDictionary() {}
  75. void EndArray() {}
  76. void SetInteger(const char* name, int value) {}
  77. void SetDouble(const char* name, double value) {}
  78. void SetBoolean(const char* name, bool value) {}
  79. void SetString(const char* name, base::StringPiece value) {}
  80. void SetValue(const char* name, TracedValue* value) {}
  81. void BeginDictionary(const char* name) {}
  82. void BeginArray(const char* name) {}
  83. void SetIntegerWithCopiedName(base::StringPiece name, int value) {}
  84. void SetDoubleWithCopiedName(base::StringPiece name, double value) {}
  85. void SetBooleanWithCopiedName(base::StringPiece name, bool value) {}
  86. void SetStringWithCopiedName(base::StringPiece name,
  87. base::StringPiece value) {}
  88. void SetValueWithCopiedName(base::StringPiece name, TracedValue* value) {}
  89. void BeginDictionaryWithCopiedName(base::StringPiece name) {}
  90. void BeginArrayWithCopiedName(base::StringPiece name) {}
  91. void AppendInteger(int) {}
  92. void AppendDouble(double) {}
  93. void AppendBoolean(bool) {}
  94. void AppendString(base::StringPiece) {}
  95. void BeginArray() {}
  96. void BeginDictionary() {}
  97. void AppendAsTraceFormat(std::string* out) const override;
  98. };
  99. class BASE_EXPORT TracedValueJSON : public TracedValue {
  100. public:
  101. explicit TracedValueJSON(size_t capacity = 0) : TracedValue(capacity) {}
  102. std::unique_ptr<base::Value> ToBaseValue() const { return nullptr; }
  103. std::string ToJSON() const { return ""; }
  104. std::string ToFormattedJSON() const { return ""; }
  105. };
  106. class BASE_EXPORT BlameContext {
  107. public:
  108. BlameContext(const char* category,
  109. const char* name,
  110. const char* type,
  111. const char* scope,
  112. int64_t id,
  113. const BlameContext* parent_context) {}
  114. void Initialize() {}
  115. void Enter() {}
  116. void Leave() {}
  117. void TakeSnapshot() {}
  118. const char* category() const { return nullptr; }
  119. const char* name() const { return nullptr; }
  120. const char* type() const { return nullptr; }
  121. const char* scope() const { return nullptr; }
  122. int64_t id() const { return 0; }
  123. };
  124. struct MemoryDumpArgs;
  125. class ProcessMemoryDump;
  126. class BASE_EXPORT MemoryDumpProvider {
  127. public:
  128. virtual ~MemoryDumpProvider();
  129. virtual bool OnMemoryDump(const MemoryDumpArgs& args,
  130. ProcessMemoryDump* pmd) = 0;
  131. protected:
  132. MemoryDumpProvider() = default;
  133. DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider);
  134. };
  135. } // namespace trace_event
  136. } // namespace base
  137. #endif // BASE_TRACE_EVENT_TRACE_EVENT_STUB_H_