Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: base/trace_event/trace_log.h

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TRACE_EVENT_TRACE_LOG_H_ 5 #ifndef BASE_TRACE_EVENT_TRACE_LOG_H_
6 #define BASE_TRACE_EVENT_TRACE_LOG_H_ 6 #define BASE_TRACE_EVENT_TRACE_LOG_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/atomicops.h" 15 #include "base/atomicops.h"
15 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
16 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/trace_event/memory_dump_provider.h" 20 #include "base/trace_event/memory_dump_provider.h"
21 #include "base/trace_event/trace_config.h" 21 #include "base/trace_event/trace_config.h"
22 #include "base/trace_event/trace_event_impl.h" 22 #include "base/trace_event/trace_event_impl.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 24
25 namespace base { 25 namespace base {
26 26
27 template <typename Type> 27 template <typename Type>
28 struct DefaultSingletonTraits; 28 struct DefaultSingletonTraits;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 TraceEventHandle AddTraceEvent( 184 TraceEventHandle AddTraceEvent(
185 char phase, 185 char phase,
186 const unsigned char* category_group_enabled, 186 const unsigned char* category_group_enabled,
187 const char* name, 187 const char* name,
188 const char* scope, 188 const char* scope,
189 unsigned long long id, 189 unsigned long long id,
190 int num_args, 190 int num_args,
191 const char** arg_names, 191 const char** arg_names,
192 const unsigned char* arg_types, 192 const unsigned char* arg_types,
193 const unsigned long long* arg_values, 193 const unsigned long long* arg_values,
194 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 194 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
195 unsigned int flags); 195 unsigned int flags);
196 TraceEventHandle AddTraceEventWithBindId( 196 TraceEventHandle AddTraceEventWithBindId(
197 char phase, 197 char phase,
198 const unsigned char* category_group_enabled, 198 const unsigned char* category_group_enabled,
199 const char* name, 199 const char* name,
200 const char* scope, 200 const char* scope,
201 unsigned long long id, 201 unsigned long long id,
202 unsigned long long bind_id, 202 unsigned long long bind_id,
203 int num_args, 203 int num_args,
204 const char** arg_names, 204 const char** arg_names,
205 const unsigned char* arg_types, 205 const unsigned char* arg_types,
206 const unsigned long long* arg_values, 206 const unsigned long long* arg_values,
207 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 207 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
208 unsigned int flags); 208 unsigned int flags);
209 TraceEventHandle AddTraceEventWithProcessId( 209 TraceEventHandle AddTraceEventWithProcessId(
210 char phase, 210 char phase,
211 const unsigned char* category_group_enabled, 211 const unsigned char* category_group_enabled,
212 const char* name, 212 const char* name,
213 const char* scope, 213 const char* scope,
214 unsigned long long id, 214 unsigned long long id,
215 int process_id, 215 int process_id,
216 int num_args, 216 int num_args,
217 const char** arg_names, 217 const char** arg_names,
218 const unsigned char* arg_types, 218 const unsigned char* arg_types,
219 const unsigned long long* arg_values, 219 const unsigned long long* arg_values,
220 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 220 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
221 unsigned int flags); 221 unsigned int flags);
222 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( 222 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp(
223 char phase, 223 char phase,
224 const unsigned char* category_group_enabled, 224 const unsigned char* category_group_enabled,
225 const char* name, 225 const char* name,
226 const char* scope, 226 const char* scope,
227 unsigned long long id, 227 unsigned long long id,
228 int thread_id, 228 int thread_id,
229 const TimeTicks& timestamp, 229 const TimeTicks& timestamp,
230 int num_args, 230 int num_args,
231 const char** arg_names, 231 const char** arg_names,
232 const unsigned char* arg_types, 232 const unsigned char* arg_types,
233 const unsigned long long* arg_values, 233 const unsigned long long* arg_values,
234 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 234 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
235 unsigned int flags); 235 unsigned int flags);
236 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( 236 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp(
237 char phase, 237 char phase,
238 const unsigned char* category_group_enabled, 238 const unsigned char* category_group_enabled,
239 const char* name, 239 const char* name,
240 const char* scope, 240 const char* scope,
241 unsigned long long id, 241 unsigned long long id,
242 unsigned long long bind_id, 242 unsigned long long bind_id,
243 int thread_id, 243 int thread_id,
244 const TimeTicks& timestamp, 244 const TimeTicks& timestamp,
245 int num_args, 245 int num_args,
246 const char** arg_names, 246 const char** arg_names,
247 const unsigned char* arg_types, 247 const unsigned char* arg_types,
248 const unsigned long long* arg_values, 248 const unsigned long long* arg_values,
249 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 249 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
250 unsigned int flags); 250 unsigned int flags);
251 251
252 // Adds a metadata event that will be written when the trace log is flushed. 252 // Adds a metadata event that will be written when the trace log is flushed.
253 void AddMetadataEvent( 253 void AddMetadataEvent(
254 const unsigned char* category_group_enabled, 254 const unsigned char* category_group_enabled,
255 const char* name, 255 const char* name,
256 int num_args, 256 int num_args,
257 const char** arg_names, 257 const char** arg_names,
258 const unsigned char* arg_types, 258 const unsigned char* arg_types,
259 const unsigned long long* arg_values, 259 const unsigned long long* arg_values,
260 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 260 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
261 unsigned int flags); 261 unsigned int flags);
262 262
263 void UpdateTraceEventDuration(const unsigned char* category_group_enabled, 263 void UpdateTraceEventDuration(const unsigned char* category_group_enabled,
264 const char* name, 264 const char* name,
265 TraceEventHandle handle); 265 TraceEventHandle handle);
266 266
267 // For every matching event, the callback will be called. 267 // For every matching event, the callback will be called.
268 typedef base::Callback<void()> WatchEventCallback; 268 typedef base::Callback<void()> WatchEventCallback;
269 void SetWatchEvent(const std::string& category_name, 269 void SetWatchEvent(const std::string& category_name,
270 const std::string& event_name, 270 const std::string& event_name,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 void FlushInternal(const OutputCallback& cb, 394 void FlushInternal(const OutputCallback& cb,
395 bool use_worker_thread, 395 bool use_worker_thread,
396 bool discard_events); 396 bool discard_events);
397 397
398 // |generation| is used in the following callbacks to check if the callback 398 // |generation| is used in the following callbacks to check if the callback
399 // is called for the flush of the current |logged_events_|. 399 // is called for the flush of the current |logged_events_|.
400 void FlushCurrentThread(int generation, bool discard_events); 400 void FlushCurrentThread(int generation, bool discard_events);
401 // Usually it runs on a different thread. 401 // Usually it runs on a different thread.
402 static void ConvertTraceEventsToTraceFormat( 402 static void ConvertTraceEventsToTraceFormat(
403 scoped_ptr<TraceBuffer> logged_events, 403 std::unique_ptr<TraceBuffer> logged_events,
404 const TraceLog::OutputCallback& flush_output_callback, 404 const TraceLog::OutputCallback& flush_output_callback,
405 const ArgumentFilterPredicate& argument_filter_predicate); 405 const ArgumentFilterPredicate& argument_filter_predicate);
406 void FinishFlush(int generation, bool discard_events); 406 void FinishFlush(int generation, bool discard_events);
407 void OnFlushTimeout(int generation, bool discard_events); 407 void OnFlushTimeout(int generation, bool discard_events);
408 408
409 int generation() const { 409 int generation() const {
410 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); 410 return static_cast<int>(subtle::NoBarrier_Load(&generation_));
411 } 411 }
412 bool CheckGeneration(int generation) const { 412 bool CheckGeneration(int generation) const {
413 return generation == this->generation(); 413 return generation == this->generation();
(...skipping 16 matching lines...) Expand all
430 static const InternalTraceOptions kInternalEnableArgumentFilter; 430 static const InternalTraceOptions kInternalEnableArgumentFilter;
431 431
432 // This lock protects TraceLog member accesses (except for members protected 432 // This lock protects TraceLog member accesses (except for members protected
433 // by thread_info_lock_) from arbitrary threads. 433 // by thread_info_lock_) from arbitrary threads.
434 mutable Lock lock_; 434 mutable Lock lock_;
435 // This lock protects accesses to thread_names_, thread_event_start_times_ 435 // This lock protects accesses to thread_names_, thread_event_start_times_
436 // and thread_colors_. 436 // and thread_colors_.
437 Lock thread_info_lock_; 437 Lock thread_info_lock_;
438 Mode mode_; 438 Mode mode_;
439 int num_traces_recorded_; 439 int num_traces_recorded_;
440 scoped_ptr<TraceBuffer> logged_events_; 440 std::unique_ptr<TraceBuffer> logged_events_;
441 std::vector<scoped_ptr<TraceEvent>> metadata_events_; 441 std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
442 subtle::AtomicWord /* EventCallback */ event_callback_; 442 subtle::AtomicWord /* EventCallback */ event_callback_;
443 bool dispatching_to_observer_list_; 443 bool dispatching_to_observer_list_;
444 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 444 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
445 445
446 std::string process_name_; 446 std::string process_name_;
447 base::hash_map<int, std::string> process_labels_; 447 base::hash_map<int, std::string> process_labels_;
448 int process_sort_index_; 448 int process_sort_index_;
449 base::hash_map<int, int> thread_sort_indices_; 449 base::hash_map<int, int> thread_sort_indices_;
450 base::hash_map<int, std::string> thread_names_; 450 base::hash_map<int, std::string> thread_names_;
451 451
(...skipping 11 matching lines...) Expand all
463 TimeDelta time_offset_; 463 TimeDelta time_offset_;
464 464
465 // Allow tests to wake up when certain events occur. 465 // Allow tests to wake up when certain events occur.
466 WatchEventCallback watch_event_callback_; 466 WatchEventCallback watch_event_callback_;
467 subtle::AtomicWord /* const unsigned char* */ watch_category_; 467 subtle::AtomicWord /* const unsigned char* */ watch_category_;
468 std::string watch_event_name_; 468 std::string watch_event_name_;
469 469
470 subtle::AtomicWord /* Options */ trace_options_; 470 subtle::AtomicWord /* Options */ trace_options_;
471 471
472 // Sampling thread handles. 472 // Sampling thread handles.
473 scoped_ptr<TraceSamplingThread> sampling_thread_; 473 std::unique_ptr<TraceSamplingThread> sampling_thread_;
474 PlatformThreadHandle sampling_thread_handle_; 474 PlatformThreadHandle sampling_thread_handle_;
475 475
476 TraceConfig trace_config_; 476 TraceConfig trace_config_;
477 TraceConfig event_callback_trace_config_; 477 TraceConfig event_callback_trace_config_;
478 478
479 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; 479 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
480 ThreadLocalBoolean thread_blocks_message_loop_; 480 ThreadLocalBoolean thread_blocks_message_loop_;
481 ThreadLocalBoolean thread_is_in_trace_event_; 481 ThreadLocalBoolean thread_is_in_trace_event_;
482 482
483 // Contains the message loops of threads that have had at least one event 483 // Contains the message loops of threads that have had at least one event
484 // added into the local event buffer. Not using SingleThreadTaskRunner 484 // added into the local event buffer. Not using SingleThreadTaskRunner
485 // because we need to know the life time of the message loops. 485 // because we need to know the life time of the message loops.
486 hash_set<MessageLoop*> thread_message_loops_; 486 hash_set<MessageLoop*> thread_message_loops_;
487 487
488 // For events which can't be added into the thread local buffer, e.g. events 488 // For events which can't be added into the thread local buffer, e.g. events
489 // from threads without a message loop. 489 // from threads without a message loop.
490 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; 490 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_;
491 size_t thread_shared_chunk_index_; 491 size_t thread_shared_chunk_index_;
492 492
493 // Set when asynchronous Flush is in progress. 493 // Set when asynchronous Flush is in progress.
494 OutputCallback flush_output_callback_; 494 OutputCallback flush_output_callback_;
495 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_; 495 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_;
496 ArgumentFilterPredicate argument_filter_predicate_; 496 ArgumentFilterPredicate argument_filter_predicate_;
497 subtle::AtomicWord generation_; 497 subtle::AtomicWord generation_;
498 bool use_worker_thread_; 498 bool use_worker_thread_;
499 499
500 DISALLOW_COPY_AND_ASSIGN(TraceLog); 500 DISALLOW_COPY_AND_ASSIGN(TraceLog);
501 }; 501 };
502 502
503 } // namespace trace_event 503 } // namespace trace_event
504 } // namespace base 504 } // namespace base
505 505
506 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ 506 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698