Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: src/oprofile-agent.cc

Issue 39179: Adding support for reporting addresses of JIT compiled code to OProfile (Closed)
Patch Set: Fixes according to Kasper's comments Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/oprofile-agent.h ('k') | src/v8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 { namespace internal {
33
34 #ifdef ENABLE_OPROFILE_AGENT
35 op_agent_t OProfileAgent::handle_ = NULL;
36 #endif
37
38
39 bool OProfileAgent::Initialize() {
40 #ifdef ENABLE_OPROFILE_AGENT
41 if (FLAG_oprofile) {
42 if (handle_ != NULL) return false;
43
44 // Disable code moving by GC.
45 FLAG_always_compact = false;
46 FLAG_never_compact = true;
47
48 handle_ = op_open_agent();
49 return (handle_ != NULL);
50 } else {
51 return true;
52 }
53 #else
54 return true;
55 #endif
56 }
57
58
59 void OProfileAgent::TearDown() {
60 #ifdef ENABLE_OPROFILE_AGENT
61 if (handle_ != NULL) {
62 op_close_agent(handle_);
63 }
64 #endif
65 }
66
67
68 void OProfileAgent::CreateNativeCodeRegion(const char* name,
69 const void* ptr, unsigned int size) {
70 #ifdef ENABLE_OPROFILE_AGENT
71 if (handle_ == NULL) return;
72 op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size);
73 #endif
74 }
75
76
77 void OProfileAgent::CreateNativeCodeRegion(String* name,
78 const void* ptr, unsigned int size) {
79 #ifdef ENABLE_OPROFILE_AGENT
80 if (handle_ != NULL) {
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 #endif
88 }
89
90
91 void OProfileAgent::CreateNativeCodeRegion(String* name, String* source,
92 int line_num, const void* ptr, unsigned int size) {
93 #ifdef ENABLE_OPROFILE_AGENT
94 if (handle_ != NULL) {
95 Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
96 const char* func_name;
97 SmartPointer<char> str =
98 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
99 func_name = name->length() > 0 ? *str : "<anonymous>";
100 SmartPointer<char> source_str =
101 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
102 if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
103 func_name, *source_str, line_num) != -1) {
104 CreateNativeCodeRegion(buf.start(), ptr, size);
105 } else {
106 CreateNativeCodeRegion("<script/func name too long>", ptr, size);
107 }
108 }
109 #endif
110 }
111 } }
OLDNEW
« no previous file with comments | « src/oprofile-agent.h ('k') | src/v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698