Chromium Code Reviews| Index: test/cctest/profiler-extension.cc |
| diff --git a/src/marking-thread.cc b/test/cctest/profiler-extension.cc |
| similarity index 54% |
| copy from src/marking-thread.cc |
| copy to test/cctest/profiler-extension.cc |
| index 574485abc7b1c7ae36c2cc04d1a2d2e663fa2921..be9462a3cfce3fce9fadbcc3bfa34d911043f7c7 100644 |
| --- a/src/marking-thread.cc |
| +++ b/test/cctest/profiler-extension.cc |
| @@ -25,64 +25,54 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -#include "marking-thread.h" |
| - |
| #include "v8.h" |
| -#include "isolate.h" |
| -#include "v8threads.h" |
| +#include "profiler-extension.h" |
| namespace v8 { |
| namespace internal { |
| -MarkingThread::MarkingThread(Isolate* isolate) |
| - : Thread("MarkingThread"), |
| - isolate_(isolate), |
| - heap_(isolate->heap()), |
| - start_marking_semaphore_(OS::CreateSemaphore(0)), |
| - end_marking_semaphore_(OS::CreateSemaphore(0)), |
| - stop_semaphore_(OS::CreateSemaphore(0)) { |
| - NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false)); |
| - id_ = NoBarrier_AtomicIncrement(&id_counter_, 1); |
| -} |
| - |
| - |
| -Atomic32 MarkingThread::id_counter_ = -1; |
| - |
| - |
| -void MarkingThread::Run() { |
| - Isolate::SetIsolateThreadLocals(isolate_, NULL); |
| - DisallowHeapAllocation no_allocation; |
| - DisallowHandleAllocation no_handles; |
| - DisallowHandleDereference no_deref; |
| - |
| - while (true) { |
| - start_marking_semaphore_->Wait(); |
| - |
| - if (Acquire_Load(&stop_thread_)) { |
| - stop_semaphore_->Signal(); |
| - return; |
| - } |
| - |
| - end_marking_semaphore_->Signal(); |
| +const char* ProfilerExtension::kSource = |
| + "native function startProfiling();" |
| + "native function stopProfiling();"; |
| + |
| +v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunction( |
| + v8::Handle<v8::String> name) { |
| + if (name->Equals(v8::String::New("startProfiling"))) { |
| + return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling); |
| + } else if (name->Equals(v8::String::New("stopProfiling"))) { |
| + return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling); |
| + } else { |
| + CHECK(false); |
|
Sven Panne
2013/06/13 09:19:12
Using FATAL with a description is more helpful and
loislo
2013/06/13 10:01:42
Done.
|
| + return v8::Handle<v8::FunctionTemplate>(); |
| } |
| } |
| -void MarkingThread::Stop() { |
| - Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); |
| - start_marking_semaphore_->Signal(); |
| - stop_semaphore_->Wait(); |
| +v8::Handle<v8::Value> ProfilerExtension::StartProfiling( |
| + const v8::Arguments& args) { |
| + v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
| + if (args.Length() > 0) |
|
Sven Panne
2013/06/13 09:19:12
Bonus points for using a ternary ?: here...
loislo
2013/06/13 10:01:42
Done.
|
| + cpu_profiler->StartCpuProfiling(args[0].As<v8::String>()); |
| + else |
| + cpu_profiler->StartCpuProfiling(v8::String::New("")); |
| + return v8::Undefined(); |
| } |
| -void MarkingThread::StartMarking() { |
| - start_marking_semaphore_->Signal(); |
| +v8::Handle<v8::Value> ProfilerExtension::StopProfiling( |
| + const v8::Arguments& args) { |
| + v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); |
| + if (args.Length() > 0) |
|
Sven Panne
2013/06/13 09:19:12
... and here. :-)
loislo
2013/06/13 10:01:42
Done.
|
| + cpu_profiler->StopCpuProfiling(args[0].As<v8::String>()); |
| + else |
| + cpu_profiler->StopCpuProfiling(v8::String::New("")); |
| + return v8::Undefined(); |
| } |
| -void MarkingThread::WaitForMarkingThread() { |
| - end_marking_semaphore_->Wait(); |
| -} |
| +static ProfilerExtension kProfilerExtension; |
| +v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension); |
|
yurys
2013/06/13 09:11:35
not lgtm
This should be done only in the tests th
yurys
2013/06/13 09:21:07
As discussed offline please disregard this comment
|
| + |
| } } // namespace v8::internal |