trace_log.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. // Copyright 2015 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_LOG_H_
  5. #define BASE_TRACE_EVENT_TRACE_LOG_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <atomic>
  9. #include <memory>
  10. #include <string>
  11. #include <unordered_map>
  12. #include <vector>
  13. #include "base/atomicops.h"
  14. #include "base/containers/stack.h"
  15. #include "base/gtest_prod_util.h"
  16. #include "base/macros.h"
  17. #include "base/memory/scoped_refptr.h"
  18. #include "base/optional.h"
  19. #include "base/single_thread_task_runner.h"
  20. #include "base/time/time_override.h"
  21. #include "base/trace_event/category_registry.h"
  22. #include "base/trace_event/memory_dump_provider.h"
  23. #include "base/trace_event/trace_config.h"
  24. #include "base/trace_event/trace_event_impl.h"
  25. #include "build/build_config.h"
  26. namespace base {
  27. class RefCountedString;
  28. template <typename T>
  29. class NoDestructor;
  30. namespace trace_event {
  31. struct TraceCategory;
  32. class TraceBuffer;
  33. class TraceBufferChunk;
  34. class TraceEvent;
  35. class TraceEventFilter;
  36. class TraceEventMemoryOverhead;
  37. struct BASE_EXPORT TraceLogStatus {
  38. TraceLogStatus();
  39. ~TraceLogStatus();
  40. uint32_t event_capacity;
  41. uint32_t event_count;
  42. };
  43. class BASE_EXPORT TraceLog : public MemoryDumpProvider {
  44. public:
  45. // Argument passed to TraceLog::SetEnabled.
  46. enum Mode : uint8_t {
  47. // Enables normal tracing (recording trace events in the trace buffer).
  48. RECORDING_MODE = 1 << 0,
  49. // Trace events are enabled just for filtering but not for recording. Only
  50. // event filters config of |trace_config| argument is used.
  51. FILTERING_MODE = 1 << 1
  52. };
  53. static TraceLog* GetInstance();
  54. // Retrieves a copy (for thread-safety) of the current TraceConfig.
  55. TraceConfig GetCurrentTraceConfig() const;
  56. // Initializes the thread-local event buffer, if not already initialized and
  57. // if the current thread supports that (has a message loop).
  58. void InitializeThreadLocalEventBufferIfSupported();
  59. // See TraceConfig comments for details on how to control which categories
  60. // will be traced. SetDisabled must be called distinctly for each mode that is
  61. // enabled. If tracing has already been enabled for recording, category filter
  62. // (enabled and disabled categories) will be merged into the current category
  63. // filter. Enabling RECORDING_MODE does not enable filters. Trace event
  64. // filters will be used only if FILTERING_MODE is set on |modes_to_enable|.
  65. // Conversely to RECORDING_MODE, FILTERING_MODE doesn't support upgrading,
  66. // i.e. filters can only be enabled if not previously enabled.
  67. void SetEnabled(const TraceConfig& trace_config, uint8_t modes_to_enable);
  68. // TODO(ssid): Remove the default SetEnabled and IsEnabled. They should take
  69. // Mode as argument.
  70. // Disables tracing for all categories for the specified |modes_to_disable|
  71. // only. Only RECORDING_MODE is taken as default |modes_to_disable|.
  72. void SetDisabled();
  73. void SetDisabled(uint8_t modes_to_disable);
  74. // Returns true if TraceLog is enabled on recording mode.
  75. // Note: Returns false even if FILTERING_MODE is enabled.
  76. bool IsEnabled() {
  77. AutoLock lock(lock_);
  78. return enabled_modes_ & RECORDING_MODE;
  79. }
  80. // Returns a bitmap of enabled modes from TraceLog::Mode.
  81. uint8_t enabled_modes() { return enabled_modes_; }
  82. // The number of times we have begun recording traces. If tracing is off,
  83. // returns -1. If tracing is on, then it returns the number of times we have
  84. // recorded a trace. By watching for this number to increment, you can
  85. // passively discover when a new trace has begun. This is then used to
  86. // implement the TRACE_EVENT_IS_NEW_TRACE() primitive.
  87. int GetNumTracesRecorded();
  88. #if defined(OS_ANDROID)
  89. void StartATrace(const std::string& category_filter);
  90. void StopATrace();
  91. void AddClockSyncMetadataEvent();
  92. void SetupATraceStartupTrace(const std::string& category_filter);
  93. Optional<TraceConfig> TakeATraceStartupConfig();
  94. #endif // defined(OS_ANDROID)
  95. // Enabled state listeners give a callback when tracing is enabled or
  96. // disabled. This can be used to tie into other library's tracing systems
  97. // on-demand.
  98. class BASE_EXPORT EnabledStateObserver {
  99. public:
  100. virtual ~EnabledStateObserver() = default;
  101. // Called just after the tracing system becomes enabled, outside of the
  102. // |lock_|. TraceLog::IsEnabled() is true at this point.
  103. virtual void OnTraceLogEnabled() = 0;
  104. // Called just after the tracing system disables, outside of the |lock_|.
  105. // TraceLog::IsEnabled() is false at this point.
  106. virtual void OnTraceLogDisabled() = 0;
  107. };
  108. // Adds an observer. Cannot be called from within the observer callback.
  109. void AddEnabledStateObserver(EnabledStateObserver* listener);
  110. // Removes an observer. Cannot be called from within the observer callback.
  111. void RemoveEnabledStateObserver(EnabledStateObserver* listener);
  112. // Adds an observer that is owned by TraceLog. This is useful for agents that
  113. // implement tracing feature that needs to stay alive as long as TraceLog
  114. // does.
  115. void AddOwnedEnabledStateObserver(
  116. std::unique_ptr<EnabledStateObserver> listener);
  117. bool HasEnabledStateObserver(EnabledStateObserver* listener) const;
  118. // Asynchronous enabled state listeners. When tracing is enabled or disabled,
  119. // for each observer, a task for invoking its appropriate callback is posted
  120. // to the thread from which AddAsyncEnabledStateObserver() was called. This
  121. // allows the observer to be safely destroyed, provided that it happens on the
  122. // same thread that invoked AddAsyncEnabledStateObserver().
  123. class BASE_EXPORT AsyncEnabledStateObserver {
  124. public:
  125. virtual ~AsyncEnabledStateObserver() = default;
  126. // Posted just after the tracing system becomes enabled, outside |lock_|.
  127. // TraceLog::IsEnabled() is true at this point.
  128. virtual void OnTraceLogEnabled() = 0;
  129. // Posted just after the tracing system becomes disabled, outside |lock_|.
  130. // TraceLog::IsEnabled() is false at this point.
  131. virtual void OnTraceLogDisabled() = 0;
  132. };
  133. // TODO(oysteine): This API originally needed to use WeakPtrs as the observer
  134. // list was copied under the global trace lock, but iterated over outside of
  135. // that lock so that observers could add tracing. The list is now protected by
  136. // its own lock, so this can be changed to a raw ptr.
  137. void AddAsyncEnabledStateObserver(
  138. WeakPtr<AsyncEnabledStateObserver> listener);
  139. void RemoveAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener);
  140. bool HasAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener) const;
  141. TraceLogStatus GetStatus() const;
  142. bool BufferIsFull() const;
  143. // Computes an estimate of the size of the TraceLog including all the retained
  144. // objects.
  145. void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead);
  146. void SetArgumentFilterPredicate(
  147. const ArgumentFilterPredicate& argument_filter_predicate);
  148. ArgumentFilterPredicate GetArgumentFilterPredicate() const;
  149. void SetMetadataFilterPredicate(
  150. const MetadataFilterPredicate& metadata_filter_predicate);
  151. MetadataFilterPredicate GetMetadataFilterPredicate() const;
  152. // Flush all collected events to the given output callback. The callback will
  153. // be called one or more times either synchronously or asynchronously from
  154. // the current thread with IPC-bite-size chunks. The string format is
  155. // undefined. Use TraceResultBuffer to convert one or more trace strings to
  156. // JSON. The callback can be null if the caller doesn't want any data.
  157. // Due to the implementation of thread-local buffers, flush can't be
  158. // done when tracing is enabled. If called when tracing is enabled, the
  159. // callback will be called directly with (empty_string, false) to indicate
  160. // the end of this unsuccessful flush. Flush does the serialization
  161. // on the same thread if the caller doesn't set use_worker_thread explicitly.
  162. using OutputCallback =
  163. base::RepeatingCallback<void(const scoped_refptr<base::RefCountedString>&,
  164. bool has_more_events)>;
  165. void Flush(const OutputCallback& cb, bool use_worker_thread = false);
  166. // Cancels tracing and discards collected data.
  167. void CancelTracing(const OutputCallback& cb);
  168. using AddTraceEventOverrideFunction = void (*)(TraceEvent*,
  169. bool thread_will_flush,
  170. TraceEventHandle* handle);
  171. using OnFlushFunction = void (*)();
  172. using UpdateDurationFunction =
  173. void (*)(const unsigned char* category_group_enabled,
  174. const char* name,
  175. TraceEventHandle handle,
  176. int thread_id,
  177. bool explicit_timestamps,
  178. const TimeTicks& now,
  179. const ThreadTicks& thread_now,
  180. ThreadInstructionCount thread_instruction_now);
  181. // The callbacks will be called up until the point where the flush is
  182. // finished, i.e. must be callable until OutputCallback is called with
  183. // has_more_events==false.
  184. void SetAddTraceEventOverrides(
  185. const AddTraceEventOverrideFunction& add_event_override,
  186. const OnFlushFunction& on_flush_callback,
  187. const UpdateDurationFunction& update_duration_callback);
  188. // Called by TRACE_EVENT* macros, don't call this directly.
  189. // The name parameter is a category group for example:
  190. // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent")
  191. static const unsigned char* GetCategoryGroupEnabled(const char* name);
  192. static const char* GetCategoryGroupName(
  193. const unsigned char* category_group_enabled);
  194. static constexpr const unsigned char* GetBuiltinCategoryEnabled(
  195. const char* name) {
  196. TraceCategory* builtin_category =
  197. CategoryRegistry::GetBuiltinCategoryByName(name);
  198. if (builtin_category)
  199. return builtin_category->state_ptr();
  200. return nullptr;
  201. }
  202. // Called by TRACE_EVENT* macros, don't call this directly.
  203. // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied
  204. // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above.
  205. bool ShouldAddAfterUpdatingState(char phase,
  206. const unsigned char* category_group_enabled,
  207. const char* name,
  208. unsigned long long id,
  209. int thread_id,
  210. TraceArguments* args);
  211. TraceEventHandle AddTraceEvent(char phase,
  212. const unsigned char* category_group_enabled,
  213. const char* name,
  214. const char* scope,
  215. unsigned long long id,
  216. TraceArguments* args,
  217. unsigned int flags);
  218. TraceEventHandle AddTraceEventWithBindId(
  219. char phase,
  220. const unsigned char* category_group_enabled,
  221. const char* name,
  222. const char* scope,
  223. unsigned long long id,
  224. unsigned long long bind_id,
  225. TraceArguments* args,
  226. unsigned int flags);
  227. TraceEventHandle AddTraceEventWithProcessId(
  228. char phase,
  229. const unsigned char* category_group_enabled,
  230. const char* name,
  231. const char* scope,
  232. unsigned long long id,
  233. int process_id,
  234. TraceArguments* args,
  235. unsigned int flags);
  236. TraceEventHandle AddTraceEventWithThreadIdAndTimestamp(
  237. char phase,
  238. const unsigned char* category_group_enabled,
  239. const char* name,
  240. const char* scope,
  241. unsigned long long id,
  242. int thread_id,
  243. const TimeTicks& timestamp,
  244. TraceArguments* args,
  245. unsigned int flags);
  246. TraceEventHandle AddTraceEventWithThreadIdAndTimestamp(
  247. char phase,
  248. const unsigned char* category_group_enabled,
  249. const char* name,
  250. const char* scope,
  251. unsigned long long id,
  252. unsigned long long bind_id,
  253. int thread_id,
  254. const TimeTicks& timestamp,
  255. TraceArguments* args,
  256. unsigned int flags);
  257. TraceEventHandle AddTraceEventWithThreadIdAndTimestamps(
  258. char phase,
  259. const unsigned char* category_group_enabled,
  260. const char* name,
  261. const char* scope,
  262. unsigned long long id,
  263. unsigned long long bind_id,
  264. int thread_id,
  265. const TimeTicks& timestamp,
  266. const ThreadTicks& thread_timestamp,
  267. TraceArguments* args,
  268. unsigned int flags);
  269. // Adds a metadata event that will be written when the trace log is flushed.
  270. void AddMetadataEvent(const unsigned char* category_group_enabled,
  271. const char* name,
  272. TraceArguments* args,
  273. unsigned int flags);
  274. void UpdateTraceEventDuration(const unsigned char* category_group_enabled,
  275. const char* name,
  276. TraceEventHandle handle);
  277. void UpdateTraceEventDurationExplicit(
  278. const unsigned char* category_group_enabled,
  279. const char* name,
  280. TraceEventHandle handle,
  281. int thread_id,
  282. bool explicit_timestamps,
  283. const TimeTicks& now,
  284. const ThreadTicks& thread_now,
  285. ThreadInstructionCount thread_instruction_now);
  286. void EndFilteredEvent(const unsigned char* category_group_enabled,
  287. const char* name,
  288. TraceEventHandle handle);
  289. int process_id() const { return process_id_; }
  290. const std::string& process_name() const { return process_name_; }
  291. uint64_t MangleEventId(uint64_t id);
  292. // Exposed for unittesting:
  293. // Testing factory for TraceEventFilter.
  294. typedef std::unique_ptr<TraceEventFilter> (*FilterFactoryForTesting)(
  295. const std::string& /* predicate_name */);
  296. void SetFilterFactoryForTesting(FilterFactoryForTesting factory) {
  297. filter_factory_for_testing_ = factory;
  298. }
  299. // Allows clearing up our singleton instance.
  300. static void ResetForTesting();
  301. // Allow tests to inspect TraceEvents.
  302. TraceEvent* GetEventByHandle(TraceEventHandle handle);
  303. void SetProcessID(int process_id);
  304. // Process sort indices, if set, override the order of a process will appear
  305. // relative to other processes in the trace viewer. Processes are sorted first
  306. // on their sort index, ascending, then by their name, and then tid.
  307. void SetProcessSortIndex(int sort_index);
  308. // Sets the name of the process.
  309. void set_process_name(const std::string& process_name) {
  310. AutoLock lock(lock_);
  311. process_name_ = process_name;
  312. }
  313. bool IsProcessNameEmpty() const { return process_name_.empty(); }
  314. // Processes can have labels in addition to their names. Use labels, for
  315. // instance, to list out the web page titles that a process is handling.
  316. void UpdateProcessLabel(int label_id, const std::string& current_label);
  317. void RemoveProcessLabel(int label_id);
  318. // Thread sort indices, if set, override the order of a thread will appear
  319. // within its process in the trace viewer. Threads are sorted first on their
  320. // sort index, ascending, then by their name, and then tid.
  321. void SetThreadSortIndex(PlatformThreadId thread_id, int sort_index);
  322. // Allow setting an offset between the current TimeTicks time and the time
  323. // that should be reported.
  324. void SetTimeOffset(TimeDelta offset);
  325. size_t GetObserverCountForTest() const;
  326. // Call this method if the current thread may block the message loop to
  327. // prevent the thread from using the thread-local buffer because the thread
  328. // may not handle the flush request in time causing lost of unflushed events.
  329. void SetCurrentThreadBlocksMessageLoop();
  330. #if defined(OS_WIN)
  331. // This function is called by the ETW exporting module whenever the ETW
  332. // keyword (flags) changes. This keyword indicates which categories should be
  333. // exported, so whenever it changes, we adjust accordingly.
  334. void UpdateETWCategoryGroupEnabledFlags();
  335. #endif
  336. // Replaces |logged_events_| with a new TraceBuffer for testing.
  337. void SetTraceBufferForTesting(std::unique_ptr<TraceBuffer> trace_buffer);
  338. private:
  339. typedef unsigned int InternalTraceOptions;
  340. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
  341. TraceBufferRingBufferGetReturnChunk);
  342. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
  343. TraceBufferRingBufferHalfIteration);
  344. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
  345. TraceBufferRingBufferFullIteration);
  346. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, TraceBufferVectorReportFull);
  347. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
  348. ConvertTraceConfigToInternalOptions);
  349. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
  350. TraceRecordAsMuchAsPossibleMode);
  351. FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, ConfigTraceBufferLimit);
  352. friend class base::NoDestructor<TraceLog>;
  353. // MemoryDumpProvider implementation.
  354. bool OnMemoryDump(const MemoryDumpArgs& args,
  355. ProcessMemoryDump* pmd) override;
  356. // Enable/disable each category group based on the current mode_,
  357. // category_filter_ and event_filters_enabled_.
  358. // Enable the category group in the recording mode if category_filter_ matches
  359. // the category group, is not null. Enable category for filtering if any
  360. // filter in event_filters_enabled_ enables it.
  361. void UpdateCategoryRegistry();
  362. void UpdateCategoryState(TraceCategory* category);
  363. void CreateFiltersForTraceConfig();
  364. InternalTraceOptions GetInternalOptionsFromTraceConfig(
  365. const TraceConfig& config);
  366. class ThreadLocalEventBuffer;
  367. class OptionalAutoLock;
  368. struct RegisteredAsyncObserver;
  369. TraceLog();
  370. ~TraceLog() override;
  371. void AddMetadataEventsWhileLocked() EXCLUSIVE_LOCKS_REQUIRED(lock_);
  372. template <typename T>
  373. void AddMetadataEventWhileLocked(int thread_id,
  374. const char* metadata_name,
  375. const char* arg_name,
  376. const T& value)
  377. EXCLUSIVE_LOCKS_REQUIRED(lock_);
  378. InternalTraceOptions trace_options() const {
  379. return static_cast<InternalTraceOptions>(
  380. subtle::NoBarrier_Load(&trace_options_));
  381. }
  382. TraceBuffer* trace_buffer() const { return logged_events_.get(); }
  383. TraceBuffer* CreateTraceBuffer();
  384. std::string EventToConsoleMessage(unsigned char phase,
  385. const TimeTicks& timestamp,
  386. TraceEvent* trace_event);
  387. TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle,
  388. bool check_buffer_is_full)
  389. EXCLUSIVE_LOCKS_REQUIRED(lock_);
  390. void CheckIfBufferIsFullWhileLocked() EXCLUSIVE_LOCKS_REQUIRED(lock_);
  391. void SetDisabledWhileLocked(uint8_t modes) EXCLUSIVE_LOCKS_REQUIRED(lock_);
  392. TraceEvent* GetEventByHandleInternal(TraceEventHandle handle,
  393. OptionalAutoLock* lock);
  394. void FlushInternal(const OutputCallback& cb,
  395. bool use_worker_thread,
  396. bool discard_events);
  397. // |generation| is used in the following callbacks to check if the callback
  398. // is called for the flush of the current |logged_events_|.
  399. void FlushCurrentThread(int generation, bool discard_events);
  400. // Usually it runs on a different thread.
  401. static void ConvertTraceEventsToTraceFormat(
  402. std::unique_ptr<TraceBuffer> logged_events,
  403. const TraceLog::OutputCallback& flush_output_callback,
  404. const ArgumentFilterPredicate& argument_filter_predicate);
  405. void FinishFlush(int generation, bool discard_events);
  406. void OnFlushTimeout(int generation, bool discard_events);
  407. int generation() const {
  408. return static_cast<int>(subtle::NoBarrier_Load(&generation_));
  409. }
  410. bool CheckGeneration(int generation) const {
  411. return generation == this->generation();
  412. }
  413. void UseNextTraceBuffer();
  414. TimeTicks OffsetNow() const {
  415. // This should be TRACE_TIME_TICKS_NOW but include order makes that hard.
  416. return OffsetTimestamp(base::subtle::TimeTicksNowIgnoringOverride());
  417. }
  418. TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const {
  419. return timestamp - time_offset_;
  420. }
  421. // Internal representation of trace options since we store the currently used
  422. // trace option as an AtomicWord.
  423. static const InternalTraceOptions kInternalNone;
  424. static const InternalTraceOptions kInternalRecordUntilFull;
  425. static const InternalTraceOptions kInternalRecordContinuously;
  426. static const InternalTraceOptions kInternalEchoToConsole;
  427. static const InternalTraceOptions kInternalRecordAsMuchAsPossible;
  428. static const InternalTraceOptions kInternalEnableArgumentFilter;
  429. // This lock protects TraceLog member accesses (except for members protected
  430. // by thread_info_lock_) from arbitrary threads.
  431. mutable Lock lock_;
  432. Lock thread_info_lock_;
  433. uint8_t enabled_modes_; // See TraceLog::Mode.
  434. int num_traces_recorded_;
  435. std::unique_ptr<TraceBuffer> logged_events_;
  436. std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
  437. // The lock protects observers access.
  438. mutable Lock observers_lock_;
  439. bool dispatching_to_observers_ = false;
  440. std::vector<EnabledStateObserver*> enabled_state_observers_
  441. GUARDED_BY(observers_lock_);
  442. std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> async_observers_
  443. GUARDED_BY(observers_lock_);
  444. // Manages ownership of the owned observers. The owned observers will also be
  445. // added to |enabled_state_observers_|.
  446. std::vector<std::unique_ptr<EnabledStateObserver>>
  447. owned_enabled_state_observer_copy_ GUARDED_BY(observers_lock_);
  448. std::string process_name_;
  449. std::unordered_map<int, std::string> process_labels_;
  450. int process_sort_index_;
  451. std::unordered_map<int, int> thread_sort_indices_;
  452. std::unordered_map<int, std::string> thread_names_
  453. GUARDED_BY(thread_info_lock_);
  454. base::Time process_creation_time_;
  455. // The following two maps are used only when ECHO_TO_CONSOLE.
  456. std::unordered_map<int, base::stack<TimeTicks>> thread_event_start_times_
  457. GUARDED_BY(thread_info_lock_);
  458. std::unordered_map<std::string, int> thread_colors_
  459. GUARDED_BY(thread_info_lock_);
  460. TimeTicks buffer_limit_reached_timestamp_;
  461. // XORed with TraceID to make it unlikely to collide with other processes.
  462. unsigned long long process_id_hash_;
  463. int process_id_;
  464. TimeDelta time_offset_;
  465. subtle::AtomicWord /* Options */ trace_options_;
  466. TraceConfig trace_config_;
  467. TraceConfig::EventFilters enabled_event_filters_;
  468. ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
  469. ThreadLocalBoolean thread_blocks_message_loop_;
  470. ThreadLocalBoolean thread_is_in_trace_event_;
  471. // Contains task runners for the threads that have had at least one event
  472. // added into the local event buffer.
  473. std::unordered_map<int, scoped_refptr<SingleThreadTaskRunner>>
  474. thread_task_runners_;
  475. // For events which can't be added into the thread local buffer, e.g. events
  476. // from threads without a message loop.
  477. std::unique_ptr<TraceBufferChunk> thread_shared_chunk_;
  478. size_t thread_shared_chunk_index_;
  479. // Set when asynchronous Flush is in progress.
  480. OutputCallback flush_output_callback_;
  481. scoped_refptr<SequencedTaskRunner> flush_task_runner_;
  482. ArgumentFilterPredicate argument_filter_predicate_;
  483. MetadataFilterPredicate metadata_filter_predicate_;
  484. subtle::AtomicWord generation_;
  485. bool use_worker_thread_;
  486. std::atomic<AddTraceEventOverrideFunction> add_trace_event_override_{nullptr};
  487. std::atomic<OnFlushFunction> on_flush_override_{nullptr};
  488. std::atomic<UpdateDurationFunction> update_duration_override_{nullptr};
  489. FilterFactoryForTesting filter_factory_for_testing_;
  490. #if defined(OS_ANDROID)
  491. base::Optional<TraceConfig> atrace_startup_config_;
  492. #endif
  493. DISALLOW_COPY_AND_ASSIGN(TraceLog);
  494. };
  495. } // namespace trace_event
  496. } // namespace base
  497. #endif // BASE_TRACE_EVENT_TRACE_LOG_H_