OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/power_profiler/devtools_power_profiler_host.h" | |
6 | |
7 #include "base/json/json_writer.h" | |
8 #include "base/logging.h" | |
9 #include "base/time/time.h" | |
10 #include "content/browser/devtools/devtools_frontend_host.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 namespace content { | |
14 | |
15 DevToolsPowerProfilerHost::DevToolsPowerProfilerHost( | |
16 const base::WeakPtr<DevToolsFrontendHost>& host) : frontend_host_(host) { | |
17 resolution_ = HIGH; | |
18 } | |
19 | |
20 void DevToolsPowerProfilerHost::convertPowerValueToJSONObject( | |
21 base::DictionaryValue* object, PowerEvent* event) { | |
22 const base::TimeTicks kNullTicks; | |
23 object->SetDouble("timestamp", convertMonotonicTimeToWallTime(event->time)); | |
24 object->SetDouble("value", event->value); | |
25 switch (event->type) { | |
26 case PowerEvent::SOC_PACKAGE: | |
27 object->SetString("type", "SoC_Package"); | |
28 break; | |
29 case PowerEvent::CPU: | |
30 object->SetString("type", "CPU"); | |
31 break; | |
32 case PowerEvent::GPU: | |
33 object->SetString("type", "GPU"); | |
34 break; | |
35 default: | |
36 NOTREACHED(); | |
37 break; | |
38 } | |
39 } | |
40 | |
41 void DevToolsPowerProfilerHost::Send(PowerEvent* buffer, int count) { | |
42 if (count <= 0) | |
43 return; | |
44 | |
45 std::string json_string; | |
46 base::DictionaryValue message_object; | |
47 base::DictionaryValue* params = new base::DictionaryValue(); | |
48 base::ListValue* event_list = new base::ListValue(); | |
49 | |
50 for (int i = 0; i < count; i++) { | |
51 base::DictionaryValue* value = new base::DictionaryValue(); | |
52 convertPowerValueToJSONObject(value, &buffer[i]); | |
53 event_list->Append(value); | |
54 } | |
55 | |
56 params->Set("powerEvents", event_list); | |
57 message_object.Set("params", params); | |
58 message_object.SetString("method", "Power.PowerEventsReceived"); | |
59 | |
60 base::JSONWriter::Write(&message_object, &json_string); | |
61 | |
62 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
63 base::Bind(&DevToolsPowerProfilerHost::SendWrapper, this, json_string)); | |
64 } | |
65 | |
66 void DevToolsPowerProfilerHost::SendWrapper(const std::string& message) { | |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
68 if (frontend_host_) | |
69 frontend_host_->DispatchOnInspectorFrontend(message); | |
70 } | |
71 | |
72 bool DevToolsPowerProfilerHost::Register() { | |
73 reference_wall_time_ = base::Time::Now().ToDoubleT(); | |
74 reference_monotonic_time_ = base::TimeTicks::Now(); | |
qsr
2014/01/17 11:50:14
Those 2 variable are not needed.
| |
75 return PowerProfilerHost::Register(); | |
76 } | |
77 | |
78 double DevToolsPowerProfilerHost::convertMonotonicTimeToWallTime( | |
qsr
2014/01/17 11:50:14
Return a base::Time() there, and compute it with:
| |
79 base::TimeTicks& tick) { | |
80 return 1000.0 * | |
81 ((tick - reference_monotonic_time_).InSecondsF() + reference_wall_time_); | |
82 } | |
83 | |
84 } // namespace base | |
OLD | NEW |