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 19 matching lines...) Expand all Loading... | |
30 #include "src/base/logging.h" | 30 #include "src/base/logging.h" |
31 #include "test/cctest/profiler-extension.h" | 31 #include "test/cctest/profiler-extension.h" |
32 | 32 |
33 namespace v8 { | 33 namespace v8 { |
34 namespace internal { | 34 namespace internal { |
35 | 35 |
36 | 36 |
37 v8::CpuProfile* ProfilerExtension::last_profile = NULL; | 37 v8::CpuProfile* ProfilerExtension::last_profile = NULL; |
38 const char* ProfilerExtension::kSource = | 38 const char* ProfilerExtension::kSource = |
39 "native function startProfiling();" | 39 "native function startProfiling();" |
40 "native function stopProfiling();"; | 40 "native function stopProfiling();" |
41 "native function collectSample();"; | |
42 | |
43 namespace { | |
44 v8::Local<v8::String> v8_str(v8::Isolate* isolate, const char* string) { | |
yurys
2016/02/05 17:33:04
Please use the one defined in v8/test/cctest/cctes
alph
2016/02/05 17:52:26
Done that, just forgot to upload. ;-)
| |
45 return v8::String::NewFromUtf8(isolate, string, v8::NewStringType::kNormal) | |
46 .ToLocalChecked(); | |
47 } | |
48 } // namespace | |
41 | 49 |
42 v8::Local<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate( | 50 v8::Local<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate( |
43 v8::Isolate* isolate, v8::Local<v8::String> name) { | 51 v8::Isolate* isolate, v8::Local<v8::String> name) { |
44 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 52 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
45 if (name->Equals(context, v8::String::NewFromUtf8(isolate, "startProfiling", | 53 if (name->Equals(context, v8_str(isolate, "startProfiling")).FromJust()) { |
46 v8::NewStringType::kNormal) | |
47 .ToLocalChecked()) | |
48 .FromJust()) { | |
49 return v8::FunctionTemplate::New(isolate, | 54 return v8::FunctionTemplate::New(isolate, |
50 ProfilerExtension::StartProfiling); | 55 ProfilerExtension::StartProfiling); |
51 } else if (name->Equals(context, | |
52 v8::String::NewFromUtf8(isolate, "stopProfiling", | |
53 v8::NewStringType::kNormal) | |
54 .ToLocalChecked()) | |
55 .FromJust()) { | |
56 return v8::FunctionTemplate::New(isolate, | |
57 ProfilerExtension::StopProfiling); | |
58 } else { | |
59 CHECK(false); | |
60 return v8::Local<v8::FunctionTemplate>(); | |
61 } | 56 } |
57 if (name->Equals(context, v8_str(isolate, "stopProfiling")).FromJust()) { | |
58 return v8::FunctionTemplate::New(isolate, ProfilerExtension::StopProfiling); | |
59 } | |
60 if (name->Equals(context, v8_str(isolate, "collectSample")).FromJust()) { | |
61 return v8::FunctionTemplate::New(isolate, ProfilerExtension::CollectSample); | |
62 } | |
63 CHECK(false); | |
64 return v8::Local<v8::FunctionTemplate>(); | |
62 } | 65 } |
63 | 66 |
64 | |
65 void ProfilerExtension::StartProfiling( | 67 void ProfilerExtension::StartProfiling( |
66 const v8::FunctionCallbackInfo<v8::Value>& args) { | 68 const v8::FunctionCallbackInfo<v8::Value>& args) { |
67 last_profile = NULL; | 69 last_profile = NULL; |
68 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | 70 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
69 cpu_profiler->StartProfiling((args.Length() > 0) | 71 cpu_profiler->StartProfiling((args.Length() > 0) |
70 ? args[0].As<v8::String>() | 72 ? args[0].As<v8::String>() |
71 : v8::String::Empty(args.GetIsolate())); | 73 : v8::String::Empty(args.GetIsolate())); |
72 } | 74 } |
73 | 75 |
74 | |
75 void ProfilerExtension::StopProfiling( | 76 void ProfilerExtension::StopProfiling( |
76 const v8::FunctionCallbackInfo<v8::Value>& args) { | 77 const v8::FunctionCallbackInfo<v8::Value>& args) { |
77 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | 78 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
78 last_profile = cpu_profiler->StopProfiling((args.Length() > 0) | 79 last_profile = cpu_profiler->StopProfiling((args.Length() > 0) |
79 ? args[0].As<v8::String>() | 80 ? args[0].As<v8::String>() |
80 : v8::String::Empty(args.GetIsolate())); | 81 : v8::String::Empty(args.GetIsolate())); |
81 } | 82 } |
82 | 83 |
84 void ProfilerExtension::CollectSample( | |
85 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
86 args.GetIsolate()->GetCpuProfiler()->CollectSample(); | |
yurys
2016/02/05 17:33:04
The whole idea of the tests that now call this nat
alph
2016/02/05 17:52:26
The tests I'm unflaking are mostly checking the st
alph
2016/02/05 18:03:33
Ok, how about I drop the CheckChildrenNames which
yurys
2016/02/05 18:07:33
Well, the tests like JsNative1JsNative2JsSample ar
| |
87 } | |
88 | |
83 } // namespace internal | 89 } // namespace internal |
84 } // namespace v8 | 90 } // namespace v8 |
OLD | NEW |