Chromium Code Reviews| 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/json/json_writer.h" | |
| 6 #include "base/strings/stringprintf.h" | |
| 5 #include "ui/events/latency_info.h" | 7 #include "ui/events/latency_info.h" |
| 6 | 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 | 10 |
| 11 namespace { | |
| 12 const char* GetComponentName(ui::LatencyComponentType type) { | |
| 13 #define CASE_TYPE(t) case ui::t: return #t | |
| 14 switch (type) { | |
| 15 CASE_TYPE(INPUT_EVENT_LATENCY_RWH_COMPONENT); | |
| 16 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT); | |
| 17 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT); | |
| 18 CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | |
| 19 CASE_TYPE(INPUT_EVENT_LATENCY_UI_COMPONENT); | |
| 20 CASE_TYPE(INPUT_EVENT_LATENCY_ACKED_MOUSE_COMPONENT); | |
| 21 CASE_TYPE(INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT); | |
| 22 CASE_TYPE(INPUT_EVENT_LATENCY_ACKED_GESTURE_COMPONENT); | |
| 23 CASE_TYPE(INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT); | |
| 24 default: | |
| 25 DLOG(WARNING) << "Unhandled LatencyComponentType.\n"; | |
| 26 break; | |
| 27 } | |
| 28 #undef CASE_TYPE | |
| 29 return "unknown"; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 9 namespace ui { | 34 namespace ui { |
| 10 | 35 |
| 36 scoped_ptr<base::debug::ConvertableToTraceFormat> | |
| 37 LatencyInfoTracedValue::FromValue(base::Value* value) { | |
| 38 LatencyInfoTracedValue* ptr = new LatencyInfoTracedValue(value); | |
| 39 scoped_ptr<LatencyInfoTracedValue> result(ptr); | |
| 40 return result.PassAs<base::debug::ConvertableToTraceFormat>(); | |
| 41 } | |
| 42 | |
| 43 LatencyInfoTracedValue::~LatencyInfoTracedValue() { | |
| 44 } | |
| 45 | |
| 46 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { | |
| 47 std::string tmp; | |
| 48 base::JSONWriter::Write(value_.get(), &tmp); | |
| 49 *out += tmp; | |
| 50 } | |
| 51 | |
| 52 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) | |
| 53 : value_(value) { | |
| 54 } | |
| 55 | |
| 11 LatencyInfo::LatencyInfo() { | 56 LatencyInfo::LatencyInfo() { |
| 12 } | 57 } |
| 13 | 58 |
| 14 LatencyInfo::~LatencyInfo() { | 59 LatencyInfo::~LatencyInfo() { |
| 15 } | 60 } |
| 16 | 61 |
| 62 void LatencyInfo::Report(LatencyComponentType terminal_component) { | |
|
nduca
2013/10/01 21:43:44
lets try putting the logic here inside the AddLate
Rick Byers
2013/10/03 13:12:41
It should be illegal to call Report more than once
Yufeng Shen (Slow to review)
2013/10/04 00:29:51
Done.
Yufeng Shen (Slow to review)
2013/10/04 00:29:51
Yes, added DCHECK to enforce that at most only one
| |
| 63 AddLatencyNumber(terminal_component, 0, 0); | |
| 64 TRACE_EVENT_INSTANT1("benchmark", | |
|
nduca
2013/10/01 21:43:44
can you try to issue async_begin and async_end tra
Yufeng Shen (Slow to review)
2013/10/04 00:29:51
Yes, we can see the grey latency rect in tracing U
| |
| 65 "LatencyInfo::IssueTraceEvent", | |
| 66 TRACE_EVENT_SCOPE_THREAD, | |
| 67 "data", AsTraceableData()); | |
| 68 } | |
| 69 | |
| 70 scoped_ptr<base::debug::ConvertableToTraceFormat> | |
| 71 LatencyInfo::AsTraceableData() const { | |
| 72 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | |
| 73 for (LatencyMap::const_iterator it = latency_components.begin(); | |
| 74 it != latency_components.end(); | |
| 75 ++it) { | |
| 76 record_data->SetString( | |
| 77 GetComponentName(it->first.first), | |
| 78 base::StringPrintf("%ld %ld %d", | |
|
nduca
2013/10/01 21:43:44
this should probably be another dict inside instad
Yufeng Shen (Slow to review)
2013/10/04 00:29:51
Done.
| |
| 79 it->first.second, | |
| 80 it->second.event_time.ToInternalValue(), | |
| 81 it->second.event_count)); | |
| 82 } | |
| 83 return LatencyInfoTracedValue::FromValue(record_data.release()); | |
| 84 } | |
| 85 | |
| 17 void LatencyInfo::MergeWith(const LatencyInfo& other) { | 86 void LatencyInfo::MergeWith(const LatencyInfo& other) { |
| 18 for (LatencyMap::const_iterator it = other.latency_components.begin(); | 87 for (LatencyMap::const_iterator it = other.latency_components.begin(); |
| 19 it != other.latency_components.end(); | 88 it != other.latency_components.end(); |
| 20 ++it) { | 89 ++it) { |
| 21 AddLatencyNumberWithTimestamp(it->first.first, | 90 AddLatencyNumberWithTimestamp(it->first.first, |
| 22 it->first.second, | 91 it->first.second, |
| 23 it->second.sequence_number, | 92 it->second.sequence_number, |
| 24 it->second.event_time, | 93 it->second.event_time, |
| 25 it->second.event_count); | 94 it->second.event_count); |
| 26 } | 95 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 if (output) | 151 if (output) |
| 83 *output = it->second; | 152 *output = it->second; |
| 84 return true; | 153 return true; |
| 85 } | 154 } |
| 86 | 155 |
| 87 void LatencyInfo::Clear() { | 156 void LatencyInfo::Clear() { |
| 88 latency_components.clear(); | 157 latency_components.clear(); |
| 89 } | 158 } |
| 90 | 159 |
| 91 } // namespace ui | 160 } // namespace ui |
| OLD | NEW |