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

Side by Side Diff: webkit/extensions/v8/profiler_extension.cc

Issue 40255: Add API functions to control Quantify, as well as expose these... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « webkit/extensions/v8/profiler_extension.h ('k') | webkit/tools/test_shell/test_shell_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 "config.h"
6 #include "webkit/extensions/v8/profiler_extension.h"
7
8 #include "base/profiler.h"
9
10 namespace extensions_v8 {
11
12 const char* kProfilerExtensionName = "v8/Profiler";
13
14 class ProfilerWrapper : public v8::Extension {
15 public:
16 ProfilerWrapper() :
17 v8::Extension(kProfilerExtensionName,
18 "if (typeof(chromium) == 'undefined') {"
19 " chromium = {};"
20 "}"
21 "chromium.Profiler = function() {"
22 " native function ProfilerStart();"
23 " native function ProfilerStop();"
24 " native function ProfilerClearData();"
25 " native function ProfilerSetThreadName();"
26 " this.start = function() {"
27 " ProfilerStart();"
28 " };"
29 " this.stop = function() {"
30 " ProfilerStop();"
31 " };"
32 " this.clear = function() {"
33 " ProfilerClearData();"
34 " };"
35 " this.setThreadName = function(name) {"
36 " ProfilerSetThreadName(name);"
37 " };"
38 "};") {}
39
40 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
41 v8::Handle<v8::String> name) {
42 if (name->Equals(v8::String::New("ProfilerStart"))) {
43 return v8::FunctionTemplate::New(ProfilerStart);
44 } else if (name->Equals(v8::String::New("ProfilerStop"))) {
45 return v8::FunctionTemplate::New(ProfilerStop);
46 } else if (name->Equals(v8::String::New("ProfilerClearData"))) {
47 return v8::FunctionTemplate::New(ProfilerClearData);
48 } else if (name->Equals(v8::String::New("ProfilerSetThreadName"))) {
49 return v8::FunctionTemplate::New(ProfilerSetThreadName);
50 }
51 return v8::Handle<v8::FunctionTemplate>();
52 }
53
54 static v8::Handle<v8::Value> ProfilerStart(
55 const v8::Arguments& args) {
56 base::Profiler::StartRecording();
57 return v8::Undefined();
58 }
59
60 static v8::Handle<v8::Value> ProfilerStop(
61 const v8::Arguments& args) {
62 base::Profiler::StopRecording();
63 return v8::Undefined();
64 }
65
66 static v8::Handle<v8::Value> ProfilerClearData(
67 const v8::Arguments& args) {
68 base::Profiler::ClearData();
69 return v8::Undefined();
70 }
71
72 static v8::Handle<v8::Value> ProfilerSetThreadName(
73 const v8::Arguments& args) {
74 if (args.Length() >= 1 && args[0]->IsString()) {
75 v8::Local<v8::String> inputString = args[0]->ToString();
76 char nameBuffer[256];
77 inputString->WriteAscii(nameBuffer, 0, sizeof(nameBuffer)-1);
78 base::Profiler::SetThreadName(nameBuffer);
79 }
80 return v8::Undefined();
81 }
82 };
83
84 v8::Extension* ProfilerExtension::Get() {
85 return new ProfilerWrapper();
86 }
87
88 } // namespace extensions_v8
89
OLDNEW
« no previous file with comments | « webkit/extensions/v8/profiler_extension.h ('k') | webkit/tools/test_shell/test_shell_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698