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

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

Issue 13590005: Add a ConvertableToTraceFormat type to the trace framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_internal.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DEBUG_TRACE_EVENT_IMPL_H_ 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_
7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 28 matching lines...) Expand all
39 39
40 template <typename Type> 40 template <typename Type>
41 struct StaticMemorySingletonTraits; 41 struct StaticMemorySingletonTraits;
42 42
43 namespace base { 43 namespace base {
44 44
45 class WaitableEvent; 45 class WaitableEvent;
46 46
47 namespace debug { 47 namespace debug {
48 48
49 // For any argument of type TRACE_VALUE_TYPE_CONVERTABLE the provided
50 // class must implement this interface.
51 class ConvertableToJSON {
nduca 2013/04/09 22:16:42 So lets call this ConvertableToTraceFormat or some
dsinclair 2013/04/10 01:09:31 Done.
52 public:
53 virtual ~ConvertableToJSON() {}
54
55 // Append the JSONified class info to the provided |out| string. The appended
56 // data must be a valid JSON object. Strings must be propertly quoted, and
57 // escaped. There is no processing applied to the content after it is
58 // appended.
59 virtual void ToJSON(std::string& out) const = 0;
nduca 2013/04/09 22:16:42 Should this use the word Append somehow?
dsinclair 2013/04/10 01:09:31 Done.
60 };
61
49 const int kTraceMaxNumArgs = 2; 62 const int kTraceMaxNumArgs = 2;
50 63
51 // Output records are "Events" and can be obtained via the 64 // Output records are "Events" and can be obtained via the
52 // OutputCallback whenever the tracing system decides to flush. This 65 // OutputCallback whenever the tracing system decides to flush. This
53 // can happen at any time, on any thread, or you can programatically 66 // can happen at any time, on any thread, or you can programatically
54 // force it to happen. 67 // force it to happen.
55 class BASE_EXPORT TraceEvent { 68 class BASE_EXPORT TraceEvent {
56 public: 69 public:
57 union TraceValue { 70 union TraceValue {
58 bool as_bool; 71 bool as_bool;
59 unsigned long long as_uint; 72 unsigned long long as_uint;
60 long long as_int; 73 long long as_int;
61 double as_double; 74 double as_double;
62 const void* as_pointer; 75 const void* as_pointer;
63 const char* as_string; 76 const char* as_string;
64 }; 77 };
65 78
66 TraceEvent(); 79 TraceEvent();
67 TraceEvent(int thread_id, 80 TraceEvent(int thread_id,
68 TimeTicks timestamp, 81 TimeTicks timestamp,
69 char phase, 82 char phase,
70 const unsigned char* category_enabled, 83 const unsigned char* category_enabled,
71 const char* name, 84 const char* name,
72 unsigned long long id, 85 unsigned long long id,
73 int num_args, 86 int num_args,
74 const char** arg_names, 87 const char** arg_names,
75 const unsigned char* arg_types, 88 const unsigned char* arg_types,
76 const unsigned long long* arg_values, 89 const unsigned long long* arg_values,
90 scoped_ptr<ConvertableToJSON> convertable_values[],
77 unsigned char flags); 91 unsigned char flags);
92 TraceEvent(const TraceEvent& other);
93 TraceEvent& operator=(const TraceEvent& other);
78 ~TraceEvent(); 94 ~TraceEvent();
79 95
80 // Serialize event data to JSON 96 // Serialize event data to JSON
81 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, 97 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events,
82 size_t start, 98 size_t start,
83 size_t count, 99 size_t count,
84 std::string* out); 100 std::string* out);
85 void AppendAsJSON(std::string* out) const; 101 void AppendAsJSON(std::string* out) const;
86 102
87 static void AppendValueAsJSON(unsigned char type, 103 static void AppendValueAsJSON(unsigned char type,
(...skipping 11 matching lines...) Expand all
99 const unsigned char* category_enabled() const { return category_enabled_; } 115 const unsigned char* category_enabled() const { return category_enabled_; }
100 const char* name() const { return name_; } 116 const char* name() const { return name_; }
101 117
102 private: 118 private:
103 // Note: these are ordered by size (largest first) for optimal packing. 119 // Note: these are ordered by size (largest first) for optimal packing.
104 TimeTicks timestamp_; 120 TimeTicks timestamp_;
105 // id_ can be used to store phase-specific data. 121 // id_ can be used to store phase-specific data.
106 unsigned long long id_; 122 unsigned long long id_;
107 TraceValue arg_values_[kTraceMaxNumArgs]; 123 TraceValue arg_values_[kTraceMaxNumArgs];
108 const char* arg_names_[kTraceMaxNumArgs]; 124 const char* arg_names_[kTraceMaxNumArgs];
125 scoped_ptr<ConvertableToJSON> convertable_values_[kTraceMaxNumArgs];
109 const unsigned char* category_enabled_; 126 const unsigned char* category_enabled_;
110 const char* name_; 127 const char* name_;
111 scoped_refptr<base::RefCountedString> parameter_copy_storage_; 128 scoped_refptr<base::RefCountedString> parameter_copy_storage_;
nduca 2013/04/09 22:16:42 we can remove this in a followup
dsinclair 2013/04/10 01:09:31 Ack.
112 int thread_id_; 129 int thread_id_;
113 char phase_; 130 char phase_;
114 unsigned char flags_; 131 unsigned char flags_;
115 unsigned char arg_types_[kTraceMaxNumArgs]; 132 unsigned char arg_types_[kTraceMaxNumArgs];
116 }; 133 };
117 134
118 // TraceBuffer holds the events as they are collected. 135 // TraceBuffer holds the events as they are collected.
119 class BASE_EXPORT TraceBuffer { 136 class BASE_EXPORT TraceBuffer {
120 public: 137 public:
121 virtual ~TraceBuffer() {} 138 virtual ~TraceBuffer() {}
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied 328 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied
312 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. 329 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above.
313 void AddTraceEvent(char phase, 330 void AddTraceEvent(char phase,
314 const unsigned char* category_enabled, 331 const unsigned char* category_enabled,
315 const char* name, 332 const char* name,
316 unsigned long long id, 333 unsigned long long id,
317 int num_args, 334 int num_args,
318 const char** arg_names, 335 const char** arg_names,
319 const unsigned char* arg_types, 336 const unsigned char* arg_types,
320 const unsigned long long* arg_values, 337 const unsigned long long* arg_values,
338 scoped_ptr<ConvertableToJSON> convertable_values[],
321 unsigned char flags); 339 unsigned char flags);
322 void AddTraceEventWithThreadIdAndTimestamp( 340 void AddTraceEventWithThreadIdAndTimestamp(
323 char phase, 341 char phase,
324 const unsigned char* category_enabled, 342 const unsigned char* category_enabled,
325 const char* name, 343 const char* name,
326 unsigned long long id, 344 unsigned long long id,
327 int thread_id, 345 int thread_id,
328 const TimeTicks& timestamp, 346 const TimeTicks& timestamp,
329 int num_args, 347 int num_args,
330 const char** arg_names, 348 const char** arg_names,
331 const unsigned char* arg_types, 349 const unsigned char* arg_types,
332 const unsigned long long* arg_values, 350 const unsigned long long* arg_values,
351 scoped_ptr<ConvertableToJSON> convertable_values[],
333 unsigned char flags); 352 unsigned char flags);
334 static void AddTraceEventEtw(char phase, 353 static void AddTraceEventEtw(char phase,
335 const char* name, 354 const char* name,
336 const void* id, 355 const void* id,
337 const char* extra); 356 const char* extra);
338 static void AddTraceEventEtw(char phase, 357 static void AddTraceEventEtw(char phase,
339 const char* name, 358 const char* name,
340 const void* id, 359 const void* id,
341 const std::string& extra); 360 const std::string& extra);
342 361
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 scoped_ptr<TraceSamplingThread> sampling_thread_; 484 scoped_ptr<TraceSamplingThread> sampling_thread_;
466 PlatformThreadHandle sampling_thread_handle_; 485 PlatformThreadHandle sampling_thread_handle_;
467 486
468 DISALLOW_COPY_AND_ASSIGN(TraceLog); 487 DISALLOW_COPY_AND_ASSIGN(TraceLog);
469 }; 488 };
470 489
471 } // namespace debug 490 } // namespace debug
472 } // namespace base 491 } // namespace base
473 492
474 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ 493 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_impl.cc » ('j') | base/debug/trace_event_internal.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698