SupervisedUser SafeSites: Switch to the new SafeSearch API
[chromium-blink-merge.git] / base / trace_event / trace_sampling_thread.h
blobf976a80e07c8d007421d11aa433a05a9cfcc188c
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"
12 namespace base {
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 {
20 public:
21 TraceSamplingThread();
22 ~TraceSamplingThread() override;
24 // Implementation of PlatformThread::Delegate:
25 void ThreadMain() override;
27 static void DefaultSamplingCallback(TraceBucketData* bucket_data);
29 void Stop();
30 void WaitSamplingEventForTesting();
32 private:
33 friend class TraceLog;
35 void GetSamples();
36 // Not thread-safe. Once the ThreadMain has been called, this can no longer
37 // be called.
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,
44 const char** name);
45 std::vector<TraceBucketData> sample_buckets_;
46 bool thread_running_;
47 CancellationFlag cancellation_flag_;
48 WaitableEvent waitable_event_for_testing_;
51 } // namespace trace_event
52 } // namespace base
54 #endif // BASE_TRACE_EVENT_TRACE_SAMPLING_THREAD_H_