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.
5 #ifndef BASE_TRACE_EVENT_TRACE_SAMPLING_THREAD_H_
6 #define BASE_TRACE_EVENT_TRACE_SAMPLING_THREAD_H_
8 #include "base/synchronization/cancellation_flag.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/trace_event/trace_event.h"
13 namespace trace_event
{
15 class TraceBucketData
;
16 typedef base::Callback
<void(TraceBucketData
*)> TraceSampleCallback
;
18 // This object must be created on the IO thread.
19 class TraceSamplingThread
: public PlatformThread::Delegate
{
21 TraceSamplingThread();
22 ~TraceSamplingThread() override
;
24 // Implementation of PlatformThread::Delegate:
25 void ThreadMain() override
;
27 static void DefaultSamplingCallback(TraceBucketData
* bucket_data
);
30 void WaitSamplingEventForTesting();
33 friend class TraceLog
;
36 // Not thread-safe. Once the ThreadMain has been called, this can no longer
38 void RegisterSampleBucket(TRACE_EVENT_API_ATOMIC_WORD
* bucket
,
39 const char* const name
,
40 TraceSampleCallback callback
);
41 // Splits a combined "category\0name" into the two component parts.
42 static void ExtractCategoryAndName(const char* combined
,
43 const char** category
,
45 std::vector
<TraceBucketData
> sample_buckets_
;
47 CancellationFlag cancellation_flag_
;
48 WaitableEvent waitable_event_for_testing_
;
51 } // namespace trace_event
54 #endif // BASE_TRACE_EVENT_TRACE_SAMPLING_THREAD_H_