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

Side by Side Diff: content/renderer/stats_collection_controller.cc

Issue 557953006: Avoid using ToInternalValue in computing timings, so that the timings are consistent accross platfo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « components/startup_metric_utils/startup_metric_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/stats_collection_controller.h" 5 #include "content/renderer/stats_collection_controller.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 // Encodes a WebContentsLoadTime as JSON. 42 // Encodes a WebContentsLoadTime as JSON.
43 // Input: 43 // Input:
44 // - |load_start_time| - time at which page load started. 44 // - |load_start_time| - time at which page load started.
45 // - |load_stop_time| - time at which page load stopped. 45 // - |load_stop_time| - time at which page load stopped.
46 // - |result| - returned JSON. 46 // - |result| - returned JSON.
47 // Example return value: 47 // Example return value:
48 // {'load_start_ms': 1, 'load_duration_ms': 2.5} 48 // {'load_start_ms': 1, 'load_duration_ms': 2.5}
49 // either value may be null if a web contents hasn't fully loaded. 49 // either value may be null if a web contents hasn't fully loaded.
50 // load_start_ms is represented as milliseconds since system boot. 50 // load_start_ms is represented as milliseconds since the unix epoch.
51 void ConvertLoadTimeToJSON( 51 void ConvertLoadTimeToJSON(
52 const base::Time& load_start_time, 52 const base::Time& load_start_time,
53 const base::Time& load_stop_time, 53 const base::Time& load_stop_time,
54 std::string *result) { 54 std::string *result) {
55 base::DictionaryValue item; 55 base::DictionaryValue item;
56 56
57 if (load_start_time.is_null()) { 57 if (load_start_time.is_null()) {
58 item.Set("load_start_ms", base::Value::CreateNullValue()); 58 item.Set("load_start_ms", base::Value::CreateNullValue());
59 } else { 59 } else {
60 item.SetDouble("load_start_ms", load_start_time.ToInternalValue() / 1000); 60 item.SetDouble("load_start_ms", (load_start_time - base::Time::UnixEpoch())
61 .InMillisecondsF());
61 } 62 }
62 if (load_start_time.is_null() || load_stop_time.is_null()) { 63 if (load_start_time.is_null() || load_stop_time.is_null()) {
63 item.Set("load_duration_ms", base::Value::CreateNullValue()); 64 item.Set("load_duration_ms", base::Value::CreateNullValue());
64 } else { 65 } else {
65 item.SetDouble("load_duration_ms", 66 item.SetDouble("load_duration_ms",
66 (load_stop_time - load_start_time).InMillisecondsF()); 67 (load_stop_time - load_start_time).InMillisecondsF());
67 } 68 }
68 base::JSONWriter::Write(&item, result); 69 base::JSONWriter::Write(&item, result);
69 } 70 }
70 71
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 151 }
151 152
152 std::string tab_timing_json; 153 std::string tab_timing_json;
153 ConvertLoadTimeToJSON( 154 ConvertLoadTimeToJSON(
154 observer->load_start_time(), observer->load_stop_time(), 155 observer->load_start_time(), observer->load_stop_time(),
155 &tab_timing_json); 156 &tab_timing_json);
156 return tab_timing_json; 157 return tab_timing_json;
157 } 158 }
158 159
159 } // namespace content 160 } // namespace content
OLDNEW
« no previous file with comments | « components/startup_metric_utils/startup_metric_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698