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

Side by Side Diff: chrome/renderer/benchmarking_extension.cc

Issue 23112028: [Telemetry] Add support for capturing V8 object stats to Telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stats_table_android
Patch Set: Sync Created 7 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 | « no previous file | tools/perf/measurements/page_cycler.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/benchmarking_extension.h" 5 #include "chrome/renderer/benchmarking_extension.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/stats_table.h" 8 #include "base/metrics/stats_table.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 11 matching lines...) Expand all
22 "if (typeof(chrome) == 'undefined') {" 22 "if (typeof(chrome) == 'undefined') {"
23 " chrome = {};" 23 " chrome = {};"
24 "};" 24 "};"
25 "if (typeof(chrome.benchmarking) == 'undefined') {" 25 "if (typeof(chrome.benchmarking) == 'undefined') {"
26 " chrome.benchmarking = {};" 26 " chrome.benchmarking = {};"
27 "};" 27 "};"
28 "chrome.benchmarking.counter = function(name) {" 28 "chrome.benchmarking.counter = function(name) {"
29 " native function GetCounter();" 29 " native function GetCounter();"
30 " return GetCounter(name);" 30 " return GetCounter(name);"
31 "};" 31 "};"
32 "chrome.benchmarking.counterForRenderer = function(name) {"
33 " native function GetCounterForRenderer();"
34 " return GetCounterForRenderer(name);"
35 "};"
32 "chrome.benchmarking.isSingleProcess = function() {" 36 "chrome.benchmarking.isSingleProcess = function() {"
33 " native function IsSingleProcess();" 37 " native function IsSingleProcess();"
34 " return IsSingleProcess();" 38 " return IsSingleProcess();"
35 "};" 39 "};"
36 "chrome.Interval = function() {" 40 "chrome.Interval = function() {"
37 " var start_ = 0;" 41 " var start_ = 0;"
38 " var stop_ = 0;" 42 " var stop_ = 0;"
39 " native function HiResTime();" 43 " native function HiResTime();"
40 " this.start = function() {" 44 " this.start = function() {"
41 " stop_ = 0;" 45 " stop_ = 0;"
(...skipping 10 matching lines...) Expand all
52 " stop = HiResTime();" 56 " stop = HiResTime();"
53 " return Math.ceil(stop - start_);" 57 " return Math.ceil(stop - start_);"
54 " };" 58 " };"
55 "}" 59 "}"
56 ) {} 60 ) {}
57 61
58 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 62 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
59 v8::Handle<v8::String> name) OVERRIDE { 63 v8::Handle<v8::String> name) OVERRIDE {
60 if (name->Equals(v8::String::New("GetCounter"))) { 64 if (name->Equals(v8::String::New("GetCounter"))) {
61 return v8::FunctionTemplate::New(GetCounter); 65 return v8::FunctionTemplate::New(GetCounter);
66 } else if (name->Equals(v8::String::New("GetCounterForRenderer"))) {
67 return v8::FunctionTemplate::New(GetCounterForRenderer);
62 } else if (name->Equals(v8::String::New("IsSingleProcess"))) { 68 } else if (name->Equals(v8::String::New("IsSingleProcess"))) {
63 return v8::FunctionTemplate::New(IsSingleProcess); 69 return v8::FunctionTemplate::New(IsSingleProcess);
64 } else if (name->Equals(v8::String::New("HiResTime"))) { 70 } else if (name->Equals(v8::String::New("HiResTime"))) {
65 return v8::FunctionTemplate::New(HiResTime); 71 return v8::FunctionTemplate::New(HiResTime);
66 } 72 }
67 73
68 return v8::Handle<v8::FunctionTemplate>(); 74 return v8::Handle<v8::FunctionTemplate>();
69 } 75 }
70 76
77 /*
78 * Extract the counter name from arguments.
79 */
80 static void ExtractCounterName(
81 const v8::FunctionCallbackInfo<v8::Value>& args,
82 char* name,
83 size_t capacity) {
84 name[0] = 'c';
85 name[1] = ':';
86 args[0]->ToString()->WriteUtf8(&name[2], capacity - 3);
87 }
88
71 static void GetCounter(const v8::FunctionCallbackInfo<v8::Value>& args) { 89 static void GetCounter(const v8::FunctionCallbackInfo<v8::Value>& args) {
72 if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current()) 90 if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current())
73 return; 91 return;
74 92
75 // Extract the name argument
76 char name[256]; 93 char name[256];
77 name[0] = 'c'; 94 ExtractCounterName(args, name, sizeof(name));
78 name[1] = ':'; 95 int counter = base::StatsTable::current()->GetCounterValue(name);
79 args[0]->ToString()->WriteUtf8(&name[2], sizeof(name) - 3); 96 args.GetReturnValue().Set(static_cast<int32_t>(counter));
97 }
80 98
81 int counter = base::StatsTable::current()->GetCounterValue(name); 99 static void GetCounterForRenderer(
100 const v8::FunctionCallbackInfo<v8::Value>& args) {
101 if (!args.Length() || !args[0]->IsString() || !base::StatsTable::current())
102 return;
103
104 char name[256];
105 ExtractCounterName(args, name, sizeof(name));
106 int counter = base::StatsTable::current()->GetCounterValue(
107 name,
108 base::GetCurrentProcId());
82 args.GetReturnValue().Set(static_cast<int32_t>(counter)); 109 args.GetReturnValue().Set(static_cast<int32_t>(counter));
83 } 110 }
84 111
85 static void IsSingleProcess(const v8::FunctionCallbackInfo<v8::Value>& args) { 112 static void IsSingleProcess(const v8::FunctionCallbackInfo<v8::Value>& args) {
86 args.GetReturnValue().Set( 113 args.GetReturnValue().Set(
87 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); 114 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess));
88 } 115 }
89 116
90 static void HiResTime(const v8::FunctionCallbackInfo<v8::Value>& args) { 117 static void HiResTime(const v8::FunctionCallbackInfo<v8::Value>& args) {
91 args.GetReturnValue().Set( 118 args.GetReturnValue().Set(
92 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue())); 119 static_cast<double>(base::TimeTicks::HighResNow().ToInternalValue()));
93 } 120 }
94 }; 121 };
95 122
96 v8::Extension* BenchmarkingExtension::Get() { 123 v8::Extension* BenchmarkingExtension::Get() {
97 return new BenchmarkingWrapper(); 124 return new BenchmarkingWrapper();
98 } 125 }
99 126
100 } // namespace extensions_v8 127 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « no previous file | tools/perf/measurements/page_cycler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698