OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "cctest.h" | 32 #include "cctest.h" |
33 | 33 |
34 const v8::CpuProfile* ProfilerExtension::last_profile = NULL; | 34 const v8::CpuProfile* ProfilerExtension::last_profile = NULL; |
35 const char* ProfilerExtension::kSource = | 35 const char* ProfilerExtension::kSource = |
36 "native function startProfiling();" | 36 "native function startProfiling();" |
37 "native function stopProfiling();"; | 37 "native function stopProfiling();"; |
38 | 38 |
39 v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate( | 39 v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate( |
40 v8::Isolate* isolate, v8::Handle<v8::String> name) { | 40 v8::Isolate* isolate, v8::Handle<v8::String> name) { |
41 if (name->Equals(v8::String::NewFromUtf8(isolate, "startProfiling"))) { | 41 if (name->Equals(v8::String::NewFromUtf8(isolate, "startProfiling"))) { |
42 return v8::FunctionTemplate::New(isolate, | 42 return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling); |
43 ProfilerExtension::StartProfiling); | |
44 } else if (name->Equals(v8::String::NewFromUtf8(isolate, "stopProfiling"))) { | 43 } else if (name->Equals(v8::String::NewFromUtf8(isolate, "stopProfiling"))) { |
45 return v8::FunctionTemplate::New(isolate, | 44 return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling); |
46 ProfilerExtension::StopProfiling); | |
47 } else { | 45 } else { |
48 CHECK(false); | 46 CHECK(false); |
49 return v8::Handle<v8::FunctionTemplate>(); | 47 return v8::Handle<v8::FunctionTemplate>(); |
50 } | 48 } |
51 } | 49 } |
52 | 50 |
53 | 51 |
54 void ProfilerExtension::StartProfiling( | 52 void ProfilerExtension::StartProfiling( |
55 const v8::FunctionCallbackInfo<v8::Value>& args) { | 53 const v8::FunctionCallbackInfo<v8::Value>& args) { |
56 last_profile = NULL; | 54 last_profile = NULL; |
57 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | 55 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
58 cpu_profiler->StartCpuProfiling((args.Length() > 0) | 56 cpu_profiler->StartCpuProfiling((args.Length() > 0) |
59 ? args[0].As<v8::String>() | 57 ? args[0].As<v8::String>() |
60 : v8::String::Empty(args.GetIsolate())); | 58 : v8::String::Empty(args.GetIsolate())); |
61 } | 59 } |
62 | 60 |
63 | 61 |
64 void ProfilerExtension::StopProfiling( | 62 void ProfilerExtension::StopProfiling( |
65 const v8::FunctionCallbackInfo<v8::Value>& args) { | 63 const v8::FunctionCallbackInfo<v8::Value>& args) { |
66 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | 64 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
67 last_profile = cpu_profiler->StopCpuProfiling((args.Length() > 0) | 65 last_profile = cpu_profiler->StopCpuProfiling((args.Length() > 0) |
68 ? args[0].As<v8::String>() | 66 ? args[0].As<v8::String>() |
69 : v8::String::Empty(args.GetIsolate())); | 67 : v8::String::Empty(args.GetIsolate())); |
70 } | 68 } |
71 | 69 |
72 | 70 |
73 static ProfilerExtension kProfilerExtension; | 71 static ProfilerExtension kProfilerExtension; |
74 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension); | 72 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension); |
OLD | NEW |