Chromium Code Reviews| Index: src/tracing/event-tracer.cc |
| diff --git a/src/tracing/event-tracer.cc b/src/tracing/event-tracer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5cedcba3fde7b212002bebdf8eba31eb8eb04e5b |
| --- /dev/null |
| +++ b/src/tracing/event-tracer.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (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 <include/v8-tracing.h> |
| + |
| +#include "src/log.h" |
| +#include "src/v8.h" |
| + |
| +class DefaultEventTracer : public v8::EventTracer { |
| + // TODO(fmeawad): remove once embedders support tracing. |
| + i::Isolate* isolate_ = i::Isolate::Current(); |
|
Yang
2015/03/13 08:07:48
- Do not use Isolate::Current anymore. We are tryi
fmeawad
2015/03/17 01:18:04
Done.
|
| + virtual v8::EventTracer::Handle addTraceEvent( |
| + char phase, const uint8_t* categoryEnabledFlag, const char* name, |
| + uint64_t id, int numArgs, const char** argNames, const uint8_t* argTypes, |
| + const uint64_t* argValues, uint8_t flags) { |
| + // TODO(fmeawad): remove the event_logger once embedders support tracing. |
| + if (isolate_ && isolate_->event_logger()) { |
| + isolate_->event_logger()(name, phase == 'B' ? 0 : 1); |
| + } |
| + return 0; |
| + } |
| + |
| + virtual void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, |
| + const char* name, |
| + EventTracer::Handle handle) {} |
| + |
| + virtual const uint8_t* getCategoryGroupEnabled(const char* name) { |
| + // TODO(fmeawad): remove the event_logger once embedders support tracing. |
| + if (isolate_ && isolate_->event_logger()) { |
| + static uint8_t yes = 0x7; |
| + return &yes; |
| + } |
| + static uint8_t no = 0; |
| + return &no; |
| + } |
| + |
| + virtual const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) { |
| + static const char* dummy = "dummy"; |
| + return dummy; |
| + } |
| +}; |
| + |
| + |
| +static void cleanup_tracer() { |
|
Yang
2015/03/13 07:52:10
I'd use CamelCase for those function names.
fmeawad
2015/03/17 01:18:04
Done.
|
| + // calling SetInstance will delete the existing instance. |
| + v8::EventTracer::SetInstance(NULL); |
| +} |
| + |
| + |
| +static void intialize_default_tracer(v8::EventTracer* current_instance) { |
| + if (current_instance == NULL) { |
| + v8::EventTracer::SetInstance(new (DefaultEventTracer)); |
| + } |
| + atexit(cleanup_tracer); |
| +} |
| + |
| + |
| +V8_DECLARE_ONCE(init_once); |
| +v8::EventTracer* v8::EventTracer::gInstance; |
| +v8::EventTracer* v8::EventTracer::GetInstance() { |
| + base::CallOnce(&init_once, intialize_default_tracer, |
| + v8::EventTracer::gInstance); |
| + DCHECK(v8::EventTracer::gInstance); |
| + return v8::EventTracer::gInstance; |
| +} |