OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 175 |
176 void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, | 176 void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, |
177 int64 id, | 177 int64 id, |
178 int64 component_sequence_number, | 178 int64 component_sequence_number, |
179 base::TimeTicks time, | 179 base::TimeTicks time, |
180 uint32 event_count) { | 180 uint32 event_count) { |
181 if (IsBeginComponent(component)) { | 181 if (IsBeginComponent(component)) { |
182 // Should only ever add begin component once. | 182 // Should only ever add begin component once. |
183 CHECK_EQ(-1, trace_id); | 183 CHECK_EQ(-1, trace_id); |
184 trace_id = component_sequence_number; | 184 trace_id = component_sequence_number; |
185 TRACE_EVENT_ASYNC_BEGIN0("benchmark", | 185 |
186 "InputLatency", | 186 // The timestamp for ASYNC_BEGIN trace event is used for drawing the |
187 TRACE_ID_DONT_MANGLE(trace_id)); | 187 // beginning of the trace event in trace viewer. For better visualization, |
188 // for an input event, we want to draw the beginning as when the event is | |
189 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, | |
190 // not when we actually issue the ASYNC_BEGIN trace event. | |
191 LatencyComponent component; | |
192 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | |
193 0, | |
194 &component) || | |
195 FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, | |
196 0, | |
197 &component)) { | |
198 // The timestamp stored in ORIGINAL/UI_COMPONENT is using CLOCK_MONOTONIC, | |
199 // while TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0 expects timestamp | |
200 // using CLOCK_MONOTONIC or CLOCK_SYSTEM_TRACE (on CrOS). So we need to | |
201 // adjust the diff between in CLOCK_MONOTONIC and CLOCK_SYSTEM_TRACE. | |
202 // Note that the diff is drifting overtime so we can't use a static value. | |
203 int64 diff = base::TimeTicks::HighResNow().ToInternalValue() - | |
dsinclair
2014/07/29 15:35:07
Do we know how expensive these two timer calls are
Yufeng Shen (Slow to review)
2014/07/29 20:01:33
Done.
| |
204 base::TimeTicks::NowFromSystemTraceTime().ToInternalValue(); | |
205 TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( | |
206 "benchmark", | |
Yufeng Shen (Slow to review)
2014/07/28 23:56:31
Hey Dan, I want to confirm with you that trace eve
dsinclair
2014/07/29 15:35:06
Why not create a TRACE_EVENT_ASYNC_BEGIN_WITH_TIME
Yufeng Shen (Slow to review)
2014/07/29 20:01:33
Done.
| |
207 "InputLatency", | |
208 TRACE_ID_DONT_MANGLE(trace_id), | |
209 static_cast<int>(base::PlatformThread::CurrentId()), | |
210 component.event_time.ToInternalValue() - diff); | |
211 } else { | |
212 TRACE_EVENT_ASYNC_BEGIN0("benchmark", | |
dsinclair
2014/07/29 15:35:06
Why not have this part of what's above and then, i
Yufeng Shen (Slow to review)
2014/07/29 20:01:33
Done.
| |
213 "InputLatency", | |
214 TRACE_ID_DONT_MANGLE(trace_id)); | |
215 } | |
216 | |
188 TRACE_EVENT_FLOW_BEGIN0( | 217 TRACE_EVENT_FLOW_BEGIN0( |
189 "input", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); | 218 "input", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); |
190 } | 219 } |
191 | 220 |
192 LatencyMap::key_type key = std::make_pair(component, id); | 221 LatencyMap::key_type key = std::make_pair(component, id); |
193 LatencyMap::iterator it = latency_components.find(key); | 222 LatencyMap::iterator it = latency_components.find(key); |
194 if (it == latency_components.end()) { | 223 if (it == latency_components.end()) { |
195 LatencyComponent info = {component_sequence_number, time, event_count}; | 224 LatencyComponent info = {component_sequence_number, time, event_count}; |
196 latency_components[key] = info; | 225 latency_components[key] = info; |
197 } else { | 226 } else { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 } | 280 } |
252 | 281 |
253 void LatencyInfo::TraceEventType(const char* event_type) { | 282 void LatencyInfo::TraceEventType(const char* event_type) { |
254 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", | 283 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", |
255 "InputLatency", | 284 "InputLatency", |
256 TRACE_ID_DONT_MANGLE(trace_id), | 285 TRACE_ID_DONT_MANGLE(trace_id), |
257 event_type); | 286 event_type); |
258 } | 287 } |
259 | 288 |
260 } // namespace ui | 289 } // namespace ui |
OLD | NEW |