OLD | NEW |
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 // This header file defines the set of trace_event macros without specifying | 5 // This header file defines the set of trace_event macros without specifying |
6 // how the events actually get collected and stored. If you need to expose trace | 6 // how the events actually get collected and stored. If you need to expose trace |
7 // events to some other universe, you can copy-and-paste this file as well as | 7 // events to some other universe, you can copy-and-paste this file as well as |
8 // trace_event.h, modifying the macros contained there as necessary for the | 8 // trace_event.h, modifying the macros contained there as necessary for the |
9 // target platform. The end result is that multiple libraries can funnel events | 9 // target platform. The end result is that multiple libraries can funnel events |
10 // through to a shared trace event collector. | 10 // through to a shared trace event collector. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // "arg1", "literal string is only referenced"); | 130 // "arg1", "literal string is only referenced"); |
131 // Use TRACE_STR_COPY to force copying of a const char*: | 131 // Use TRACE_STR_COPY to force copying of a const char*: |
132 // TRACE_EVENT1("category", "name", | 132 // TRACE_EVENT1("category", "name", |
133 // "arg1", TRACE_STR_COPY("string will be copied")); | 133 // "arg1", TRACE_STR_COPY("string will be copied")); |
134 // std::string arg_values are always copied: | 134 // std::string arg_values are always copied: |
135 // TRACE_EVENT1("category", "name", | 135 // TRACE_EVENT1("category", "name", |
136 // "arg1", std::string("string will be copied")); | 136 // "arg1", std::string("string will be copied")); |
137 // | 137 // |
138 // | 138 // |
139 // Convertable notes: | 139 // Convertable notes: |
140 // Converting a large data type to a string can be costly. To help with this, | 140 // Unlike base's trace framework, no convertable support in Blink because of |
141 // the trace framework provides an interface ConvertableToTraceFormat. If you | 141 // the way we estimate tracing memory overhead. All objects passed to the |
142 // inherit from it and implement the AppendAsTraceFormat method the trace | 142 // tracing framework should be allocated by malloc to calculate overhead |
143 // framework will call back to your object to convert a trace output time. This | 143 // correctly, while many Blink objects use PartitionAlloc/Oilpan. Convertable |
144 // means, if the category for the event is disabled, the conversion will not | 144 // is an interface to avoid unnecessary conversion but if we allow to use |
145 // happen. | 145 // PartitionAlloc/Oilpan backed objects, overhead estimation could be wrong. |
| 146 // For structured objects, you can use TracedValue. |
146 // | 147 // |
147 // class MyData : public base::trace_event::ConvertableToTraceFormat { | 148 // class MyData { |
148 // public: | 149 // public: |
149 // MyData() {} | 150 // MyData() {} |
150 // void AppendAsTraceFormat(std::string* out) const override { | 151 // PassRefPtr<TracedValue> toTracedValue() { |
151 // out->append("{\"foo\":1}"); | 152 // RefPtr<TracedValue> tracedValue = TracedValue::create(); |
| 153 // tracedValue->setInteger("foo", 1); |
| 154 // tracedValue->beginArray("bar"); |
| 155 // tracedValue->pushInteger(2); |
| 156 // tracedValue->pushInteger(3); |
| 157 // tracedValue->endArray(); |
| 158 // return tracedValue.release(); |
152 // } | 159 // } |
153 // private: | 160 // private: |
154 // ~MyData() override {} | 161 // ~MyData() override {} |
155 // DISALLOW_COPY_AND_ASSIGN(MyData); | |
156 // }; | 162 // }; |
157 // | 163 // |
158 // TRACE_EVENT1("foo", "bar", "data", | 164 // TRACE_EVENT1("foo", "bar", "data", myData.toTracedValue()); |
159 // scoped_refptr<ConvertableToTraceFormat>(new MyData())); | |
160 // | 165 // |
161 // The trace framework will take ownership if the passed pointer and it will | 166 // The trace framework will take ownership. |
162 // be free'd when the trace buffer is flushed. | |
163 // | |
164 // Note, we only do the conversion when the buffer is flushed, so the provided | |
165 // data object should not be modified after it's passed to the trace framework. | |
166 // | 167 // |
167 // | 168 // |
168 // Thread Safety: | 169 // Thread Safety: |
169 // A thread safe singleton and mutex are used for thread safety. Category | 170 // A thread safe singleton and mutex are used for thread safety. Category |
170 // enabled flags are used to limit the performance impact when the system | 171 // enabled flags are used to limit the performance impact when the system |
171 // is not enabled. | 172 // is not enabled. |
172 // | 173 // |
173 // TRACE_EVENT macros first cache a pointer to a category. The categories are | 174 // TRACE_EVENT macros first cache a pointer to a category. The categories are |
174 // statically allocated and safe at all times, even after exit. Fetching a | 175 // statically allocated and safe at all times, even after exit. Fetching a |
175 // category is protected by the TraceLog::lock_. Multiple threads initializing | 176 // category is protected by the TraceLog::lock_. Multiple threads initializing |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 1048 |
1048 // Enum reflecting the scope of an INSTANT event. Must fit within | 1049 // Enum reflecting the scope of an INSTANT event. Must fit within |
1049 // TRACE_EVENT_FLAG_SCOPE_MASK. | 1050 // TRACE_EVENT_FLAG_SCOPE_MASK. |
1050 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) | 1051 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) |
1051 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) | 1052 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) |
1052 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) | 1053 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) |
1053 | 1054 |
1054 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') | 1055 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') |
1055 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') | 1056 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') |
1056 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') | 1057 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') |
OLD | NEW |