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

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

Issue 1115023003: [Startup Tracing] The TraceConfig class [STALE] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test for GetSyntheticDelayValues Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 5
6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_
7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ 7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_
8 8
9 #include <stack> 9 #include <stack>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/memory/ref_counted_memory.h" 18 #include "base/memory/ref_counted_memory.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/synchronization/condition_variable.h" 23 #include "base/synchronization/condition_variable.h"
24 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "base/threading/thread_local.h" 26 #include "base/threading/thread_local.h"
27 #include "base/values.h"
27 28
28 // Older style trace macros with explicit id and extra data 29 // Older style trace macros with explicit id and extra data
29 // Only these macros result in publishing data to ETW as currently implemented. 30 // Only these macros result in publishing data to ETW as currently implemented.
30 // TODO(georgesak): Update/replace these with new ETW macros. 31 // TODO(georgesak): Update/replace these with new ETW macros.
31 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ 32 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \
32 base::trace_event::TraceLog::AddTraceEventEtw( \ 33 base::trace_event::TraceLog::AddTraceEventEtw( \
33 TRACE_EVENT_PHASE_BEGIN, \ 34 TRACE_EVENT_PHASE_BEGIN, \
34 name, reinterpret_cast<const void*>(id), extra) 35 name, reinterpret_cast<const void*>(id), extra)
35 36
36 #define TRACE_EVENT_END_ETW(name, id, extra) \ 37 #define TRACE_EVENT_END_ETW(name, id, extra) \
37 base::trace_event::TraceLog::AddTraceEventEtw( \ 38 base::trace_event::TraceLog::AddTraceEventEtw( \
38 TRACE_EVENT_PHASE_END, \ 39 TRACE_EVENT_PHASE_END, \
39 name, reinterpret_cast<const void*>(id), extra) 40 name, reinterpret_cast<const void*>(id), extra)
40 41
41 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ 42 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \
42 base::trace_event::TraceLog::AddTraceEventEtw( \ 43 base::trace_event::TraceLog::AddTraceEventEtw( \
43 TRACE_EVENT_PHASE_INSTANT, \ 44 TRACE_EVENT_PHASE_INSTANT, \
44 name, reinterpret_cast<const void*>(id), extra) 45 name, reinterpret_cast<const void*>(id), extra)
45 46
46 template <typename Type> 47 template <typename Type>
47 struct DefaultSingletonTraits; 48 struct DefaultSingletonTraits;
48 49
49 namespace base { 50 namespace base {
50 51
51 class WaitableEvent; 52 class WaitableEvent;
52 class MessageLoop; 53 class MessageLoop;
53 54
54 namespace trace_event { 55 namespace trace_event {
55 56
57 class CategoryFilter;
58
56 // For any argument of type TRACE_VALUE_TYPE_CONVERTABLE the provided 59 // For any argument of type TRACE_VALUE_TYPE_CONVERTABLE the provided
57 // class must implement this interface. 60 // class must implement this interface.
58 class BASE_EXPORT ConvertableToTraceFormat 61 class BASE_EXPORT ConvertableToTraceFormat
59 : public RefCounted<ConvertableToTraceFormat> { 62 : public RefCounted<ConvertableToTraceFormat> {
60 public: 63 public:
61 // Append the class info to the provided |out| string. The appended 64 // Append the class info to the provided |out| string. The appended
62 // data must be a valid JSON object. Strings must be properly quoted, and 65 // data must be a valid JSON object. Strings must be properly quoted, and
63 // escaped. There is no processing applied to the content after it is 66 // escaped. There is no processing applied to the content after it is
64 // appended. 67 // appended.
65 virtual void AppendAsTraceFormat(std::string* out) const = 0; 68 virtual void AppendAsTraceFormat(std::string* out) const = 0;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 271
269 // When all fragments have been added, call Finish to complete the JSON 272 // When all fragments have been added, call Finish to complete the JSON
270 // formatted output. 273 // formatted output.
271 void Finish(); 274 void Finish();
272 275
273 private: 276 private:
274 OutputCallback output_callback_; 277 OutputCallback output_callback_;
275 bool append_comma_; 278 bool append_comma_;
276 }; 279 };
277 280
281 // Options determines how the trace buffer stores data.
282 enum TraceRecordMode {
283 // Record until the trace buffer is full.
284 RECORD_UNTIL_FULL,
285
286 // Record until the user ends the trace. The trace buffer is a fixed size
287 // and we use it as a ring buffer during recording.
288 RECORD_CONTINUOUSLY,
289
290 // Echo to console. Events are discarded.
291 ECHO_TO_CONSOLE,
292
293 // Record until the trace buffer is full, but with a huge buffer size.
294 RECORD_AS_MUCH_AS_POSSIBLE
295 };
296
297 struct BASE_EXPORT TraceOptions {
298 TraceOptions()
299 : record_mode(RECORD_UNTIL_FULL),
300 enable_sampling(false),
301 enable_systrace(false) {}
302
303 explicit TraceOptions(TraceRecordMode record_mode)
304 : record_mode(record_mode),
305 enable_sampling(false),
306 enable_systrace(false) {}
307
308 // |options_string| is a comma-delimited list of trace options.
309 // Possible options are: "record-until-full", "record-continuously",
310 // "trace-to-console", "enable-sampling" and "enable-systrace".
311 // The first 3 options are trace recoding modes and hence
312 // mutually exclusive. If more than one trace recording modes appear in the
313 // options_string, the last one takes precedence. If none of the trace
314 // recording mode is specified, recording mode is RECORD_UNTIL_FULL.
315 //
316 // The trace option will first be reset to the default option
317 // (record_mode set to RECORD_UNTIL_FULL, enable_sampling and enable_systrace
318 // set to false) before options parsed from |options_string| are applied on
319 // it.
320 // If |options_string| is invalid, the final state of trace_options is
321 // undefined.
322 //
323 // Example: trace_options.SetFromString("record-until-full")
324 // Example: trace_options.SetFromString(
325 // "record-continuously, enable-sampling")
326 // Example: trace_options.SetFromString("record-until-full, trace-to-console")
327 // will set ECHO_TO_CONSOLE as the recording mode.
328 //
329 // Returns true on success.
330 bool SetFromString(const std::string& options_string);
331
332 std::string ToString() const;
333
334 TraceRecordMode record_mode;
335 bool enable_sampling;
336 bool enable_systrace;
337 };
338
339 class BASE_EXPORT TraceConfig {
dsinclair 2015/05/21 13:42:08 This file is getting pretty big, lets split these
Zhen Wang 2015/05/22 23:38:04 I move TraceConfig, CategoryFilter and TraceOption
340 public:
341 typedef std::vector<std::string> StringList;
342
343 TraceConfig();
344
345 // Create TraceConfig object from CategoryFilter and TraceOptions.
346 TraceConfig(const CategoryFilter& cf, const TraceOptions& options);
347
348 // Create TraceConfig object from category filter and trace options strings.
349 TraceConfig(const std::string& category_filter_string,
350 const std::string& trace_options_string);
351
352 // |config_string| is a dictionary formatted as a JSON string, containing both
353 // category filters and trace options.
354 explicit TraceConfig(const std::string& config_string);
355
356 explicit TraceConfig(const TraceConfig& tc);
357
358 ~TraceConfig();
359
360 TraceConfig& operator=(const TraceConfig& rhs);
361
362 // Return a list of the synthetic delays specified in this category filter.
363 const StringList& GetSyntheticDelayValues() const;
364
365 // Convert TraceConfig to the dict representation of the TraceConfig.
366 void ToDict(base::DictionaryValue& dict) const;
367
368 // Writes the string representation of the TraceConfig. The string is JSON
369 // formatted.
370 std::string ToString() const;
371
372 // Write the string representation of the CategoryFilter part.
373 std::string ToCategoryFilterString() const;
374
375 // Write the string representation of the TraceOptions part.
376 std::string ToTraceOptionsString() const;
377
378 // Returns true if at least one category in the list is enabled by this
379 // trace config.
380 bool IsCategoryGroupEnabled(const char* category_group) const;
381
382 // Merges config with the current TraceConfig
383 void Merge(const TraceConfig& config);
384
385 void Clear();
386
387 private:
388 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyStrings);
389 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
390 TraceConfigFromInvalidLegacyStrings);
391 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig);
392 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString);
393 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString);
394 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
395 IsEmptyOrContainsLeadingOrTrailingWhitespace);
396 friend class CategoryFilter;
397
398 void Initialize(const std::string& config_string);
399
400 // The default trace config, used when none is provided.
401 // Allows all categories through, except if they end in the suffix 'Debug' or
402 // 'Test'.
dsinclair 2015/05/21 13:42:08 I still think this comment is wrong. It doesn't al
Zhen Wang 2015/05/22 23:38:04 I think the comment is correct. See TraceConfigTes
dsinclair 2015/05/25 13:36:02 If the comment is correct, then the code is wrong
403 void InitializeDefault();
404
405 void SetCategoriesFromList(StringList& categories,
406 const base::ListValue& list);
407 void SetSyntheticDelaysFromList(StringList& delays,
408 const base::ListValue& list);
409 void AddCategoryToDict(base::DictionaryValue& dict,
410 const char* param,
411 const StringList& categories) const;
412
413 // Returns true if category is enable according to this trace config.
414 bool IsCategoryEnabled(const char* category_name) const;
415
416 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
417 const std::string& str);
418
419 bool HasIncludedPatterns() const;
420
421 TraceRecordMode record_mode_;
422 bool enable_sampling_;
423 bool enable_systrace_;
424
425 StringList included_categories_;
426 StringList disabled_categories_;
427 StringList excluded_categories_;
428 StringList synthetic_delays_;
429 };
430
278 class BASE_EXPORT CategoryFilter { 431 class BASE_EXPORT CategoryFilter {
279 public: 432 public:
280 typedef std::vector<std::string> StringList; 433 typedef std::vector<std::string> StringList;
281 434
282 // The default category filter, used when none is provided. 435 // The default category filter, used when none is provided.
283 // Allows all categories through, except if they end in the suffix 'Debug' or 436 // Allows all categories through, except if they end in the suffix 'Debug' or
284 // 'Test'. 437 // 'Test'.
285 static const char kDefaultCategoryFilterString[]; 438 static const char kDefaultCategoryFilterString[];
286 439
287 // |filter_string| is a comma-delimited list of category wildcards. 440 // |filter_string| is a comma-delimited list of category wildcards.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // Clears both included/excluded pattern lists. This would be equivalent to 488 // Clears both included/excluded pattern lists. This would be equivalent to
336 // creating a CategoryFilter with an empty string, through the constructor. 489 // creating a CategoryFilter with an empty string, through the constructor.
337 // i.e: CategoryFilter(). 490 // i.e: CategoryFilter().
338 // 491 //
339 // When using an empty filter, all categories are considered included as we 492 // When using an empty filter, all categories are considered included as we
340 // are not excluding anything. 493 // are not excluding anything.
341 void Clear(); 494 void Clear();
342 495
343 private: 496 private:
344 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter); 497 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter);
498 friend class TraceConfig;
345 499
346 // Returns true if category is enable according to this filter. 500 // Returns true if category is enable according to this filter.
347 bool IsCategoryEnabled(const char* category_name) const; 501 bool IsCategoryEnabled(const char* category_name) const;
348 502
349 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( 503 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
350 const std::string& str); 504 const std::string& str);
351 505
352 void Initialize(const std::string& filter_string); 506 void Initialize(const std::string& filter_string);
353 void WriteString(const StringList& values, 507 void WriteString(const StringList& values,
354 std::string* out, 508 std::string* out,
355 bool included) const; 509 bool included) const;
356 void WriteString(const StringList& delays, std::string* out) const; 510 void WriteString(const StringList& delays, std::string* out) const;
357 bool HasIncludedPatterns() const; 511 bool HasIncludedPatterns() const;
358 512
359 StringList included_; 513 TraceConfig config_;
360 StringList disabled_;
361 StringList excluded_;
362 StringList delays_;
363 }; 514 };
364 515
365 class TraceSamplingThread; 516 class TraceSamplingThread;
366 517
367 // Options determines how the trace buffer stores data.
368 enum TraceRecordMode {
369 // Record until the trace buffer is full.
370 RECORD_UNTIL_FULL,
371
372 // Record until the user ends the trace. The trace buffer is a fixed size
373 // and we use it as a ring buffer during recording.
374 RECORD_CONTINUOUSLY,
375
376 // Echo to console. Events are discarded.
377 ECHO_TO_CONSOLE,
378
379 // Record until the trace buffer is full, but with a huge buffer size.
380 RECORD_AS_MUCH_AS_POSSIBLE
381 };
382
383 struct BASE_EXPORT TraceOptions {
384 TraceOptions()
385 : record_mode(RECORD_UNTIL_FULL),
386 enable_sampling(false),
387 enable_systrace(false) {}
388
389 explicit TraceOptions(TraceRecordMode record_mode)
390 : record_mode(record_mode),
391 enable_sampling(false),
392 enable_systrace(false) {}
393
394 // |options_string| is a comma-delimited list of trace options.
395 // Possible options are: "record-until-full", "record-continuously",
396 // "trace-to-console", "enable-sampling" and "enable-systrace".
397 // The first 3 options are trace recoding modes and hence
398 // mutually exclusive. If more than one trace recording modes appear in the
399 // options_string, the last one takes precedence. If none of the trace
400 // recording mode is specified, recording mode is RECORD_UNTIL_FULL.
401 //
402 // The trace option will first be reset to the default option
403 // (record_mode set to RECORD_UNTIL_FULL, enable_sampling and enable_systrace
404 // set to false) before options parsed from |options_string| are applied on
405 // it.
406 // If |options_string| is invalid, the final state of trace_options is
407 // undefined.
408 //
409 // Example: trace_options.SetFromString("record-until-full")
410 // Example: trace_options.SetFromString(
411 // "record-continuously, enable-sampling")
412 // Example: trace_options.SetFromString("record-until-full, trace-to-console")
413 // will set ECHO_TO_CONSOLE as the recording mode.
414 //
415 // Returns true on success.
416 bool SetFromString(const std::string& options_string);
417
418 std::string ToString() const;
419
420 TraceRecordMode record_mode;
421 bool enable_sampling;
422 bool enable_systrace;
423 };
424
425 struct BASE_EXPORT TraceLogStatus { 518 struct BASE_EXPORT TraceLogStatus {
426 TraceLogStatus(); 519 TraceLogStatus();
427 ~TraceLogStatus(); 520 ~TraceLogStatus();
428 size_t event_capacity; 521 size_t event_capacity;
429 size_t event_count; 522 size_t event_count;
430 }; 523 };
431 524
432 class BASE_EXPORT TraceLog { 525 class BASE_EXPORT TraceLog {
433 public: 526 public:
434 enum Mode { 527 enum Mode {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 subtle::AtomicWord generation_; 907 subtle::AtomicWord generation_;
815 bool use_worker_thread_; 908 bool use_worker_thread_;
816 909
817 DISALLOW_COPY_AND_ASSIGN(TraceLog); 910 DISALLOW_COPY_AND_ASSIGN(TraceLog);
818 }; 911 };
819 912
820 } // namespace trace_event 913 } // namespace trace_event
821 } // namespace base 914 } // namespace base
822 915
823 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ 916 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | base/trace_event/trace_event_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698