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

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: rebase 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/trace_event/trace_config.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) \
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 273
273 // When all fragments have been added, call Finish to complete the JSON 274 // When all fragments have been added, call Finish to complete the JSON
274 // formatted output. 275 // formatted output.
275 void Finish(); 276 void Finish();
276 277
277 private: 278 private:
278 OutputCallback output_callback_; 279 OutputCallback output_callback_;
279 bool append_comma_; 280 bool append_comma_;
280 }; 281 };
281 282
282 class BASE_EXPORT CategoryFilter {
283 public:
284 typedef std::vector<std::string> StringList;
285
286 // The default category filter, used when none is provided.
287 // Allows all categories through, except if they end in the suffix 'Debug' or
288 // 'Test'.
289 static const char kDefaultCategoryFilterString[];
290
291 // |filter_string| is a comma-delimited list of category wildcards.
292 // A category can have an optional '-' prefix to make it an excluded category.
293 // All the same rules apply above, so for example, having both included and
294 // excluded categories in the same list would not be supported.
295 //
296 // Example: CategoryFilter"test_MyTest*");
297 // Example: CategoryFilter("test_MyTest*,test_OtherStuff");
298 // Example: CategoryFilter("-excluded_category1,-excluded_category2");
299 // Example: CategoryFilter("-*,webkit"); would disable everything but webkit.
300 // Example: CategoryFilter("-webkit"); would enable everything but webkit.
301 //
302 // Category filters can also be used to configure synthetic delays.
303 //
304 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16)"); would make swap
305 // buffers always take at least 16 ms.
306 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16;oneshot)"); would
307 // make swap buffers take at least 16 ms the first time it is
308 // called.
309 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16;alternating)");
310 // would make swap buffers take at least 16 ms every other time it
311 // is called.
312 explicit CategoryFilter(const std::string& filter_string);
313
314 CategoryFilter();
315
316 CategoryFilter(const CategoryFilter& cf);
317
318 ~CategoryFilter();
319
320 CategoryFilter& operator=(const CategoryFilter& rhs);
321
322 // Writes the string representation of the CategoryFilter. This is a comma
323 // separated string, similar in nature to the one used to determine
324 // enabled/disabled category patterns, except here there is an arbitrary
325 // order, included categories go first, then excluded categories. Excluded
326 // categories are distinguished from included categories by the prefix '-'.
327 std::string ToString() const;
328
329 // Returns true if at least one category in the list is enabled by this
330 // category filter.
331 bool IsCategoryGroupEnabled(const char* category_group) const;
332
333 // Return a list of the synthetic delays specified in this category filter.
334 const StringList& GetSyntheticDelayValues() const;
335
336 // Merges nested_filter with the current CategoryFilter
337 void Merge(const CategoryFilter& nested_filter);
338
339 // Clears both included/excluded pattern lists. This would be equivalent to
340 // creating a CategoryFilter with an empty string, through the constructor.
341 // i.e: CategoryFilter().
342 //
343 // When using an empty filter, all categories are considered included as we
344 // are not excluding anything.
345 void Clear();
346
347 private:
348 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter);
349
350 // Returns true if category is enable according to this filter.
351 bool IsCategoryEnabled(const char* category_name) const;
352
353 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
354 const std::string& str);
355
356 void Initialize(const std::string& filter_string);
357 void WriteString(const StringList& values,
358 std::string* out,
359 bool included) const;
360 void WriteString(const StringList& delays, std::string* out) const;
361 bool HasIncludedPatterns() const;
362
363 StringList included_;
364 StringList disabled_;
365 StringList excluded_;
366 StringList delays_;
367 };
368
369 class TraceSamplingThread; 283 class TraceSamplingThread;
370 284
371 // Options determines how the trace buffer stores data.
372 enum TraceRecordMode {
373 // Record until the trace buffer is full.
374 RECORD_UNTIL_FULL,
375
376 // Record until the user ends the trace. The trace buffer is a fixed size
377 // and we use it as a ring buffer during recording.
378 RECORD_CONTINUOUSLY,
379
380 // Echo to console. Events are discarded.
381 ECHO_TO_CONSOLE,
382
383 // Record until the trace buffer is full, but with a huge buffer size.
384 RECORD_AS_MUCH_AS_POSSIBLE
385 };
386
387 struct BASE_EXPORT TraceOptions {
388 TraceOptions()
389 : record_mode(RECORD_UNTIL_FULL),
390 enable_sampling(false),
391 enable_systrace(false),
392 enable_argument_filter(false) {}
393
394 explicit TraceOptions(TraceRecordMode record_mode)
395 : record_mode(record_mode),
396 enable_sampling(false),
397 enable_systrace(false),
398 enable_argument_filter(false) {}
399
400 // |options_string| is a comma-delimited list of trace options.
401 // Possible options are: "record-until-full", "record-continuously",
402 // "trace-to-console", "enable-sampling" and "enable-systrace".
403 // The first 3 options are trace recoding modes and hence
404 // mutually exclusive. If more than one trace recording modes appear in the
405 // options_string, the last one takes precedence. If none of the trace
406 // recording mode is specified, recording mode is RECORD_UNTIL_FULL.
407 //
408 // The trace option will first be reset to the default option
409 // (record_mode set to RECORD_UNTIL_FULL, enable_sampling and enable_systrace
410 // set to false) before options parsed from |options_string| are applied on
411 // it.
412 // If |options_string| is invalid, the final state of trace_options is
413 // undefined.
414 //
415 // Example: trace_options.SetFromString("record-until-full")
416 // Example: trace_options.SetFromString(
417 // "record-continuously, enable-sampling")
418 // Example: trace_options.SetFromString("record-until-full, trace-to-console")
419 // will set ECHO_TO_CONSOLE as the recording mode.
420 //
421 // Returns true on success.
422 bool SetFromString(const std::string& options_string);
423
424 std::string ToString() const;
425
426 TraceRecordMode record_mode;
427 bool enable_sampling;
428 bool enable_systrace;
429 bool enable_argument_filter;
430 };
431
432 struct BASE_EXPORT TraceLogStatus { 285 struct BASE_EXPORT TraceLogStatus {
433 TraceLogStatus(); 286 TraceLogStatus();
434 ~TraceLogStatus(); 287 ~TraceLogStatus();
435 size_t event_capacity; 288 size_t event_capacity;
436 size_t event_count; 289 size_t event_count;
437 }; 290 };
438 291
439 class BASE_EXPORT TraceLog { 292 class BASE_EXPORT TraceLog {
440 public: 293 public:
441 enum Mode { 294 enum Mode {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 subtle::AtomicWord generation_; 679 subtle::AtomicWord generation_;
827 bool use_worker_thread_; 680 bool use_worker_thread_;
828 681
829 DISALLOW_COPY_AND_ASSIGN(TraceLog); 682 DISALLOW_COPY_AND_ASSIGN(TraceLog);
830 }; 683 };
831 684
832 } // namespace trace_event 685 } // namespace trace_event
833 } // namespace base 686 } // namespace base
834 687
835 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ 688 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698