OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #include <include/v8-tracing.h> | |
29 | |
30 #include "src/log.h" | |
31 #include "src/v8.h" | |
32 | |
33 class DefaultEventTracer : public v8::EventTracer { | |
34 // TODO(fmeawad): remove once embedders support tracing. | |
35 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.
| |
36 virtual v8::EventTracer::Handle addTraceEvent( | |
37 char phase, const uint8_t* categoryEnabledFlag, const char* name, | |
38 uint64_t id, int numArgs, const char** argNames, const uint8_t* argTypes, | |
39 const uint64_t* argValues, uint8_t flags) { | |
40 // TODO(fmeawad): remove the event_logger once embedders support tracing. | |
41 if (isolate_ && isolate_->event_logger()) { | |
42 isolate_->event_logger()(name, phase == 'B' ? 0 : 1); | |
43 } | |
44 return 0; | |
45 } | |
46 | |
47 virtual void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, | |
48 const char* name, | |
49 EventTracer::Handle handle) {} | |
50 | |
51 virtual const uint8_t* getCategoryGroupEnabled(const char* name) { | |
52 // TODO(fmeawad): remove the event_logger once embedders support tracing. | |
53 if (isolate_ && isolate_->event_logger()) { | |
54 static uint8_t yes = 0x7; | |
55 return &yes; | |
56 } | |
57 static uint8_t no = 0; | |
58 return &no; | |
59 } | |
60 | |
61 virtual const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) { | |
62 static const char* dummy = "dummy"; | |
63 return dummy; | |
64 } | |
65 }; | |
66 | |
67 | |
68 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.
| |
69 // calling SetInstance will delete the existing instance. | |
70 v8::EventTracer::SetInstance(NULL); | |
71 } | |
72 | |
73 | |
74 static void intialize_default_tracer(v8::EventTracer* current_instance) { | |
75 if (current_instance == NULL) { | |
76 v8::EventTracer::SetInstance(new (DefaultEventTracer)); | |
77 } | |
78 atexit(cleanup_tracer); | |
79 } | |
80 | |
81 | |
82 V8_DECLARE_ONCE(init_once); | |
83 v8::EventTracer* v8::EventTracer::gInstance; | |
84 v8::EventTracer* v8::EventTracer::GetInstance() { | |
85 base::CallOnce(&init_once, intialize_default_tracer, | |
86 v8::EventTracer::gInstance); | |
87 DCHECK(v8::EventTracer::gInstance); | |
88 return v8::EventTracer::gInstance; | |
89 } | |
OLD | NEW |