Align OProfile agent invocations style with logging.

This allows to unclutter logging-related code.
I also fixed compilation issues with 'profilingsupport=off'.

Review URL: http://codereview.chromium.org/1317003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4285 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 203ba181
...@@ -61,13 +61,9 @@ void CodeStub::GenerateCode(MacroAssembler* masm) { ...@@ -61,13 +61,9 @@ void CodeStub::GenerateCode(MacroAssembler* masm) {
void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) { void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) {
code->set_major_key(MajorKey()); code->set_major_key(MajorKey());
#ifdef ENABLE_OPROFILE_AGENT OPROFILE(CreateNativeCodeRegion(GetName(),
// Register the generated stub with the OPROFILE agent. code->instruction_start(),
OProfileAgent::CreateNativeCodeRegion(GetName(), code->instruction_size()));
code->instruction_start(),
code->instruction_size());
#endif
LOG(CodeCreateEvent(Logger::STUB_TAG, code, GetName())); LOG(CodeCreateEvent(Logger::STUB_TAG, code, GetName()));
Counters::total_stubs_code_size.Increment(code->instruction_size()); Counters::total_stubs_code_size.Increment(code->instruction_size());
......
...@@ -235,27 +235,19 @@ static Handle<SharedFunctionInfo> MakeFunctionInfo(bool is_global, ...@@ -235,27 +235,19 @@ static Handle<SharedFunctionInfo> MakeFunctionInfo(bool is_global,
return Handle<SharedFunctionInfo>::null(); return Handle<SharedFunctionInfo>::null();
} }
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT if (script->name()->IsString()) {
// Log the code generation for the script. Check explicit whether logging is LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
// to avoid allocating when not required. *code, String::cast(script->name())));
if (Logger::is_logging() || OProfileAgent::is_enabled()) { OPROFILE(CreateNativeCodeRegion(String::cast(script->name()),
if (script->name()->IsString()) { code->instruction_start(),
SmartPointer<char> data = code->instruction_size()));
String::cast(script->name())->ToCString(DISALLOW_NULLS); } else {
LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG, LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
*code, *data)); *code, ""));
OProfileAgent::CreateNativeCodeRegion(*data, OPROFILE(CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
code->instruction_start(), code->instruction_start(),
code->instruction_size()); code->instruction_size()));
} else {
LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
*code, ""));
OProfileAgent::CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
code->instruction_start(),
code->instruction_size());
}
} }
#endif
// Allocate function. // Allocate function.
Handle<SharedFunctionInfo> result = Handle<SharedFunctionInfo> result =
...@@ -443,14 +435,12 @@ bool Compiler::CompileLazy(CompilationInfo* info) { ...@@ -443,14 +435,12 @@ bool Compiler::CompileLazy(CompilationInfo* info) {
return false; return false;
} }
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG,
LogCodeCreateEvent(Logger::LAZY_COMPILE_TAG, name,
name, Handle<String>(shared->inferred_name()),
Handle<String>(shared->inferred_name()), start_position,
start_position, info->script(),
info->script(), code);
code);
#endif
// Update the shared function info with the compiled code. // Update the shared function info with the compiled code.
shared->set_code(*code); shared->set_code(*code);
...@@ -578,15 +568,12 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, ...@@ -578,15 +568,12 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
} }
// Function compilation complete. // Function compilation complete.
RecordFunctionCompilation(Logger::FUNCTION_TAG,
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT literal->name(),
LogCodeCreateEvent(Logger::FUNCTION_TAG, literal->inferred_name(),
literal->name(), literal->start_position(),
literal->inferred_name(), script,
literal->start_position(), code);
script,
code);
#endif
} }
// Create a boilerplate function. // Create a boilerplate function.
...@@ -628,13 +615,12 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, ...@@ -628,13 +615,12 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
} }
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag, Handle<String> name,
Handle<String> name, Handle<String> inferred_name,
Handle<String> inferred_name, int start_position,
int start_position, Handle<Script> script,
Handle<Script> script, Handle<Code> code) {
Handle<Code> code) {
// Log the code generation. If source information is available // Log the code generation. If source information is available
// include script name and line number. Check explicitly whether // include script name and line number. Check explicitly whether
// logging is enabled as finding the line number is not free. // logging is enabled as finding the line number is not free.
...@@ -642,21 +628,21 @@ void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag, ...@@ -642,21 +628,21 @@ void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag,
Handle<String> func_name(name->length() > 0 ? *name : *inferred_name); Handle<String> func_name(name->length() > 0 ? *name : *inferred_name);
if (script->name()->IsString()) { if (script->name()->IsString()) {
int line_num = GetScriptLineNumber(script, start_position) + 1; int line_num = GetScriptLineNumber(script, start_position) + 1;
USE(line_num);
LOG(CodeCreateEvent(tag, *code, *func_name, LOG(CodeCreateEvent(tag, *code, *func_name,
String::cast(script->name()), line_num)); String::cast(script->name()), line_num));
OProfileAgent::CreateNativeCodeRegion(*func_name, OPROFILE(CreateNativeCodeRegion(*func_name,
String::cast(script->name()), String::cast(script->name()),
line_num, line_num,
code->instruction_start(), code->instruction_start(),
code->instruction_size()); code->instruction_size()));
} else { } else {
LOG(CodeCreateEvent(tag, *code, *func_name)); LOG(CodeCreateEvent(tag, *code, *func_name));
OProfileAgent::CreateNativeCodeRegion(*func_name, OPROFILE(CreateNativeCodeRegion(*func_name,
code->instruction_start(), code->instruction_start(),
code->instruction_size()); code->instruction_size()));
} }
} }
} }
#endif
} } // namespace v8::internal } } // namespace v8::internal
...@@ -266,15 +266,12 @@ class Compiler : public AllStatic { ...@@ -266,15 +266,12 @@ class Compiler : public AllStatic {
Handle<Script> script); Handle<Script> script);
private: private:
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT Handle<String> name,
static void LogCodeCreateEvent(Logger::LogEventsAndTags tag, Handle<String> inferred_name,
Handle<String> name, int start_position,
Handle<String> inferred_name, Handle<Script> script,
int start_position, Handle<Code> code);
Handle<Script> script,
Handle<Code> code);
#endif
}; };
......
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
#ifdef ENABLE_OPROFILE_AGENT
op_agent_t OProfileAgent::handle_ = NULL;
#endif
bool OProfileAgent::Initialize() { bool OProfileAgent::Initialize() {
#ifdef ENABLE_OPROFILE_AGENT #ifdef ENABLE_OPROFILE_AGENT
...@@ -70,47 +66,43 @@ void OProfileAgent::TearDown() { ...@@ -70,47 +66,43 @@ void OProfileAgent::TearDown() {
} }
#ifdef ENABLE_OPROFILE_AGENT
op_agent_t OProfileAgent::handle_ = NULL;
void OProfileAgent::CreateNativeCodeRegion(const char* name, void OProfileAgent::CreateNativeCodeRegion(const char* name,
const void* ptr, unsigned int size) { const void* ptr, unsigned int size) {
#ifdef ENABLE_OPROFILE_AGENT
if (handle_ == NULL) return;
op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size); op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size);
#endif
} }
void OProfileAgent::CreateNativeCodeRegion(String* name, void OProfileAgent::CreateNativeCodeRegion(String* name,
const void* ptr, unsigned int size) { const void* ptr, unsigned int size) {
#ifdef ENABLE_OPROFILE_AGENT const char* func_name;
if (handle_ != NULL) { SmartPointer<char> str =
const char* func_name; name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
SmartPointer<char> str = func_name = name->length() > 0 ? *str : "<anonymous>";
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); CreateNativeCodeRegion(func_name, ptr, size);
func_name = name->length() > 0 ? *str : "<anonymous>";
CreateNativeCodeRegion(func_name, ptr, size);
}
#endif
} }
void OProfileAgent::CreateNativeCodeRegion(String* name, String* source, void OProfileAgent::CreateNativeCodeRegion(String* name, String* source,
int line_num, const void* ptr, unsigned int size) { int line_num, const void* ptr, unsigned int size) {
#ifdef ENABLE_OPROFILE_AGENT Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
if (handle_ != NULL) { const char* func_name;
Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize); SmartPointer<char> str =
const char* func_name; name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
SmartPointer<char> str = func_name = name->length() > 0 ? *str : "<anonymous>";
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); SmartPointer<char> source_str =
func_name = name->length() > 0 ? *str : "<anonymous>"; source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
SmartPointer<char> source_str = if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); func_name, *source_str, line_num) != -1) {
if (v8::internal::OS::SNPrintF(buf, "%s %s:%d", CreateNativeCodeRegion(buf.start(), ptr, size);
func_name, *source_str, line_num) != -1) { } else {
CreateNativeCodeRegion(buf.start(), ptr, size); CreateNativeCodeRegion("<script/func name too long>", ptr, size);
} else {
CreateNativeCodeRegion("<script/func name too long>", ptr, size);
}
} }
#endif
} }
} }
#endif // ENABLE_OPROFILE_AGENT
} } // namespace v8::internal
...@@ -37,6 +37,14 @@ ...@@ -37,6 +37,14 @@
// system headers (they have __uint64_t), but is defined // system headers (they have __uint64_t), but is defined
// in V8's headers. // in V8's headers.
#include <opagent.h> // NOLINT #include <opagent.h> // NOLINT
#define OPROFILE(Call) \
do { \
if (v8::internal::OProfileAgent::is_enabled()) \
v8::internal::OProfileAgent::Call; \
} while (false)
#else
#define OPROFILE(Call) ((void) 0)
#endif #endif
namespace v8 { namespace v8 {
...@@ -46,13 +54,13 @@ class OProfileAgent { ...@@ -46,13 +54,13 @@ class OProfileAgent {
public: public:
static bool Initialize(); static bool Initialize();
static void TearDown(); static void TearDown();
#ifdef ENABLE_OPROFILE_AGENT
static void CreateNativeCodeRegion(const char* name, static void CreateNativeCodeRegion(const char* name,
const void* ptr, unsigned int size); const void* ptr, unsigned int size);
static void CreateNativeCodeRegion(String* name, static void CreateNativeCodeRegion(String* name,
const void* ptr, unsigned int size); const void* ptr, unsigned int size);
static void CreateNativeCodeRegion(String* name, String* source, int line_num, static void CreateNativeCodeRegion(String* name, String* source, int line_num,
const void* ptr, unsigned int size); const void* ptr, unsigned int size);
#ifdef ENABLE_OPROFILE_AGENT
static bool is_enabled() { return handle_ != NULL; } static bool is_enabled() { return handle_ != NULL; }
private: private:
......
...@@ -505,7 +505,6 @@ class Socket { ...@@ -505,7 +505,6 @@ class Socket {
}; };
#ifdef ENABLE_LOGGING_AND_PROFILING
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Sampler // Sampler
// //
...@@ -533,6 +532,7 @@ class TickSample { ...@@ -533,6 +532,7 @@ class TickSample {
int frames_count; // Number of captured frames. int frames_count; // Number of captured frames.
}; };
#ifdef ENABLE_LOGGING_AND_PROFILING
class Sampler { class Sampler {
public: public:
// Initialize sampler. // Initialize sampler.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment