| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "oprofile-agent.h" | 30 #include "oprofile-agent.h" |
| 31 | 31 |
| 32 namespace v8 { | 32 namespace v8 { |
| 33 namespace internal { | 33 namespace internal { |
| 34 | 34 |
| 35 #ifdef ENABLE_OPROFILE_AGENT | |
| 36 op_agent_t OProfileAgent::handle_ = NULL; | |
| 37 #endif | |
| 38 | |
| 39 | 35 |
| 40 bool OProfileAgent::Initialize() { | 36 bool OProfileAgent::Initialize() { |
| 41 #ifdef ENABLE_OPROFILE_AGENT | 37 #ifdef ENABLE_OPROFILE_AGENT |
| 42 if (FLAG_oprofile) { | 38 if (FLAG_oprofile) { |
| 43 if (handle_ != NULL) return false; | 39 if (handle_ != NULL) return false; |
| 44 | 40 |
| 45 // Disable code moving by GC. | 41 // Disable code moving by GC. |
| 46 FLAG_always_compact = false; | 42 FLAG_always_compact = false; |
| 47 FLAG_never_compact = true; | 43 FLAG_never_compact = true; |
| 48 | 44 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 63 | 59 |
| 64 void OProfileAgent::TearDown() { | 60 void OProfileAgent::TearDown() { |
| 65 #ifdef ENABLE_OPROFILE_AGENT | 61 #ifdef ENABLE_OPROFILE_AGENT |
| 66 if (handle_ != NULL) { | 62 if (handle_ != NULL) { |
| 67 op_close_agent(handle_); | 63 op_close_agent(handle_); |
| 68 } | 64 } |
| 69 #endif | 65 #endif |
| 70 } | 66 } |
| 71 | 67 |
| 72 | 68 |
| 69 #ifdef ENABLE_OPROFILE_AGENT |
| 70 op_agent_t OProfileAgent::handle_ = NULL; |
| 71 |
| 72 |
| 73 void OProfileAgent::CreateNativeCodeRegion(const char* name, | 73 void OProfileAgent::CreateNativeCodeRegion(const char* name, |
| 74 const void* ptr, unsigned int size) { | 74 const void* ptr, unsigned int size) { |
| 75 #ifdef ENABLE_OPROFILE_AGENT | |
| 76 if (handle_ == NULL) return; | |
| 77 op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size); | 75 op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size); |
| 78 #endif | |
| 79 } | 76 } |
| 80 | 77 |
| 81 | 78 |
| 82 void OProfileAgent::CreateNativeCodeRegion(String* name, | 79 void OProfileAgent::CreateNativeCodeRegion(String* name, |
| 83 const void* ptr, unsigned int size) { | 80 const void* ptr, unsigned int size) { |
| 84 #ifdef ENABLE_OPROFILE_AGENT | 81 const char* func_name; |
| 85 if (handle_ != NULL) { | 82 SmartPointer<char> str = |
| 86 const char* func_name; | 83 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 87 SmartPointer<char> str = | 84 func_name = name->length() > 0 ? *str : "<anonymous>"; |
| 88 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 85 CreateNativeCodeRegion(func_name, ptr, size); |
| 89 func_name = name->length() > 0 ? *str : "<anonymous>"; | |
| 90 CreateNativeCodeRegion(func_name, ptr, size); | |
| 91 } | |
| 92 #endif | |
| 93 } | 86 } |
| 94 | 87 |
| 95 | 88 |
| 96 void OProfileAgent::CreateNativeCodeRegion(String* name, String* source, | 89 void OProfileAgent::CreateNativeCodeRegion(String* name, String* source, |
| 97 int line_num, const void* ptr, unsigned int size) { | 90 int line_num, const void* ptr, unsigned int size) { |
| 98 #ifdef ENABLE_OPROFILE_AGENT | 91 Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize); |
| 99 if (handle_ != NULL) { | 92 const char* func_name; |
| 100 Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize); | 93 SmartPointer<char> str = |
| 101 const char* func_name; | 94 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 102 SmartPointer<char> str = | 95 func_name = name->length() > 0 ? *str : "<anonymous>"; |
| 103 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 96 SmartPointer<char> source_str = |
| 104 func_name = name->length() > 0 ? *str : "<anonymous>"; | 97 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 105 SmartPointer<char> source_str = | 98 if (v8::internal::OS::SNPrintF(buf, "%s %s:%d", |
| 106 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 99 func_name, *source_str, line_num) != -1) { |
| 107 if (v8::internal::OS::SNPrintF(buf, "%s %s:%d", | 100 CreateNativeCodeRegion(buf.start(), ptr, size); |
| 108 func_name, *source_str, line_num) != -1) { | 101 } else { |
| 109 CreateNativeCodeRegion(buf.start(), ptr, size); | 102 CreateNativeCodeRegion("<script/func name too long>", ptr, size); |
| 110 } else { | |
| 111 CreateNativeCodeRegion("<script/func name too long>", ptr, size); | |
| 112 } | |
| 113 } | 103 } |
| 114 #endif | |
| 115 } | 104 } |
| 116 } } | 105 |
| 106 #endif // ENABLE_OPROFILE_AGENT |
| 107 |
| 108 } } // namespace v8::internal |
| OLD | NEW |