OLD | NEW |
| (Empty) |
1 // Copyright 2006-2009 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 "v8.h" | |
29 | |
30 #include "oprofile-agent.h" | |
31 | |
32 namespace v8 { | |
33 namespace internal { | |
34 | |
35 | |
36 bool OProfileAgent::Initialize() { | |
37 #ifdef ENABLE_OPROFILE_AGENT | |
38 if (FLAG_oprofile) { | |
39 if (handle_ != NULL) return false; | |
40 | |
41 // Disable code moving by GC. | |
42 FLAG_always_compact = false; | |
43 FLAG_never_compact = true; | |
44 | |
45 handle_ = op_open_agent(); | |
46 return (handle_ != NULL); | |
47 } else { | |
48 return true; | |
49 } | |
50 #else | |
51 if (FLAG_oprofile) { | |
52 OS::Print("Warning: --oprofile specified but binary compiled without " | |
53 "oprofile support.\n"); | |
54 } | |
55 return true; | |
56 #endif | |
57 } | |
58 | |
59 | |
60 void OProfileAgent::TearDown() { | |
61 #ifdef ENABLE_OPROFILE_AGENT | |
62 if (handle_ != NULL) { | |
63 op_close_agent(handle_); | |
64 } | |
65 #endif | |
66 } | |
67 | |
68 | |
69 #ifdef ENABLE_OPROFILE_AGENT | |
70 op_agent_t OProfileAgent::handle_ = NULL; | |
71 | |
72 | |
73 void OProfileAgent::CreateNativeCodeRegion(const char* name, | |
74 const void* ptr, unsigned int size) { | |
75 op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size); | |
76 } | |
77 | |
78 | |
79 void OProfileAgent::CreateNativeCodeRegion(String* name, | |
80 const void* ptr, unsigned int size) { | |
81 const char* func_name; | |
82 SmartPointer<char> str = | |
83 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | |
84 func_name = name->length() > 0 ? *str : "<anonymous>"; | |
85 CreateNativeCodeRegion(func_name, ptr, size); | |
86 } | |
87 | |
88 | |
89 void OProfileAgent::CreateNativeCodeRegion(String* name, String* source, | |
90 int line_num, const void* ptr, unsigned int size) { | |
91 Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize); | |
92 const char* func_name; | |
93 SmartPointer<char> str = | |
94 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | |
95 func_name = name->length() > 0 ? *str : "<anonymous>"; | |
96 SmartPointer<char> source_str = | |
97 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | |
98 if (v8::internal::OS::SNPrintF(buf, "%s %s:%d", | |
99 func_name, *source_str, line_num) != -1) { | |
100 CreateNativeCodeRegion(buf.start(), ptr, size); | |
101 } else { | |
102 CreateNativeCodeRegion("<script/func name too long>", ptr, size); | |
103 } | |
104 } | |
105 | |
106 #endif // ENABLE_OPROFILE_AGENT | |
107 | |
108 } } // namespace v8::internal | |
OLD | NEW |