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
This commit is contained in:
mikhail.naganov@gmail.com 2010-03-25 14:55:53 +00:00
parent 203ba181ad
commit 27663efb85
6 changed files with 83 additions and 104 deletions

View File

@ -61,13 +61,9 @@ void CodeStub::GenerateCode(MacroAssembler* masm) {
void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) {
code->set_major_key(MajorKey());
#ifdef ENABLE_OPROFILE_AGENT
// Register the generated stub with the OPROFILE agent.
OProfileAgent::CreateNativeCodeRegion(GetName(),
code->instruction_start(),
code->instruction_size());
#endif
OPROFILE(CreateNativeCodeRegion(GetName(),
code->instruction_start(),
code->instruction_size()));
LOG(CodeCreateEvent(Logger::STUB_TAG, code, GetName()));
Counters::total_stubs_code_size.Increment(code->instruction_size());

View File

@ -235,27 +235,19 @@ static Handle<SharedFunctionInfo> MakeFunctionInfo(bool is_global,
return Handle<SharedFunctionInfo>::null();
}
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
// Log the code generation for the script. Check explicit whether logging is
// to avoid allocating when not required.
if (Logger::is_logging() || OProfileAgent::is_enabled()) {
if (script->name()->IsString()) {
SmartPointer<char> data =
String::cast(script->name())->ToCString(DISALLOW_NULLS);
LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
*code, *data));
OProfileAgent::CreateNativeCodeRegion(*data,
code->instruction_start(),
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());
}
if (script->name()->IsString()) {
LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
*code, String::cast(script->name())));
OPROFILE(CreateNativeCodeRegion(String::cast(script->name()),
code->instruction_start(),
code->instruction_size()));
} else {
LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
*code, ""));
OPROFILE(CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
code->instruction_start(),
code->instruction_size()));
}
#endif
// Allocate function.
Handle<SharedFunctionInfo> result =
@ -443,14 +435,12 @@ bool Compiler::CompileLazy(CompilationInfo* info) {
return false;
}
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
LogCodeCreateEvent(Logger::LAZY_COMPILE_TAG,
name,
Handle<String>(shared->inferred_name()),
start_position,
info->script(),
code);
#endif
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG,
name,
Handle<String>(shared->inferred_name()),
start_position,
info->script(),
code);
// Update the shared function info with the compiled code.
shared->set_code(*code);
@ -578,15 +568,12 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
}
// Function compilation complete.
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
LogCodeCreateEvent(Logger::FUNCTION_TAG,
literal->name(),
literal->inferred_name(),
literal->start_position(),
script,
code);
#endif
RecordFunctionCompilation(Logger::FUNCTION_TAG,
literal->name(),
literal->inferred_name(),
literal->start_position(),
script,
code);
}
// Create a boilerplate function.
@ -628,13 +615,12 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
}
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag,
Handle<String> name,
Handle<String> inferred_name,
int start_position,
Handle<Script> script,
Handle<Code> code) {
void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
Handle<String> name,
Handle<String> inferred_name,
int start_position,
Handle<Script> script,
Handle<Code> code) {
// Log the code generation. If source information is available
// include script name and line number. Check explicitly whether
// logging is enabled as finding the line number is not free.
@ -642,21 +628,21 @@ void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag,
Handle<String> func_name(name->length() > 0 ? *name : *inferred_name);
if (script->name()->IsString()) {
int line_num = GetScriptLineNumber(script, start_position) + 1;
USE(line_num);
LOG(CodeCreateEvent(tag, *code, *func_name,
String::cast(script->name()), line_num));
OProfileAgent::CreateNativeCodeRegion(*func_name,
String::cast(script->name()),
line_num,
code->instruction_start(),
code->instruction_size());
OPROFILE(CreateNativeCodeRegion(*func_name,
String::cast(script->name()),
line_num,
code->instruction_start(),
code->instruction_size()));
} else {
LOG(CodeCreateEvent(tag, *code, *func_name));
OProfileAgent::CreateNativeCodeRegion(*func_name,
code->instruction_start(),
code->instruction_size());
OPROFILE(CreateNativeCodeRegion(*func_name,
code->instruction_start(),
code->instruction_size()));
}
}
}
#endif
} } // namespace v8::internal

View File

@ -266,15 +266,12 @@ class Compiler : public AllStatic {
Handle<Script> script);
private:
#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
static void LogCodeCreateEvent(Logger::LogEventsAndTags tag,
Handle<String> name,
Handle<String> inferred_name,
int start_position,
Handle<Script> script,
Handle<Code> code);
#endif
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
Handle<String> name,
Handle<String> inferred_name,
int start_position,
Handle<Script> script,
Handle<Code> code);
};

View File

@ -32,10 +32,6 @@
namespace v8 {
namespace internal {
#ifdef ENABLE_OPROFILE_AGENT
op_agent_t OProfileAgent::handle_ = NULL;
#endif
bool OProfileAgent::Initialize() {
#ifdef ENABLE_OPROFILE_AGENT
@ -70,47 +66,43 @@ void OProfileAgent::TearDown() {
}
#ifdef ENABLE_OPROFILE_AGENT
op_agent_t OProfileAgent::handle_ = NULL;
void OProfileAgent::CreateNativeCodeRegion(const char* name,
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);
#endif
}
void OProfileAgent::CreateNativeCodeRegion(String* name,
const void* ptr, unsigned int size) {
#ifdef ENABLE_OPROFILE_AGENT
if (handle_ != NULL) {
const char* func_name;
SmartPointer<char> str =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
func_name = name->length() > 0 ? *str : "<anonymous>";
CreateNativeCodeRegion(func_name, ptr, size);
}
#endif
const char* func_name;
SmartPointer<char> str =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
func_name = name->length() > 0 ? *str : "<anonymous>";
CreateNativeCodeRegion(func_name, ptr, size);
}
void OProfileAgent::CreateNativeCodeRegion(String* name, String* source,
int line_num, const void* ptr, unsigned int size) {
#ifdef ENABLE_OPROFILE_AGENT
if (handle_ != NULL) {
Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
const char* func_name;
SmartPointer<char> str =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
func_name = name->length() > 0 ? *str : "<anonymous>";
SmartPointer<char> source_str =
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
func_name, *source_str, line_num) != -1) {
CreateNativeCodeRegion(buf.start(), ptr, size);
} else {
CreateNativeCodeRegion("<script/func name too long>", ptr, size);
}
Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
const char* func_name;
SmartPointer<char> str =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
func_name = name->length() > 0 ? *str : "<anonymous>";
SmartPointer<char> source_str =
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
func_name, *source_str, line_num) != -1) {
CreateNativeCodeRegion(buf.start(), ptr, size);
} else {
CreateNativeCodeRegion("<script/func name too long>", ptr, size);
}
#endif
}
} }
#endif // ENABLE_OPROFILE_AGENT
} } // namespace v8::internal

View File

@ -37,6 +37,14 @@
// system headers (they have __uint64_t), but is defined
// in V8's headers.
#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
namespace v8 {
@ -46,13 +54,13 @@ class OProfileAgent {
public:
static bool Initialize();
static void TearDown();
#ifdef ENABLE_OPROFILE_AGENT
static void CreateNativeCodeRegion(const char* name,
const void* ptr, unsigned int size);
static void CreateNativeCodeRegion(String* name,
const void* ptr, unsigned int size);
static void CreateNativeCodeRegion(String* name, String* source, int line_num,
const void* ptr, unsigned int size);
#ifdef ENABLE_OPROFILE_AGENT
static bool is_enabled() { return handle_ != NULL; }
private:

View File

@ -505,7 +505,6 @@ class Socket {
};
#ifdef ENABLE_LOGGING_AND_PROFILING
// ----------------------------------------------------------------------------
// Sampler
//
@ -533,6 +532,7 @@ class TickSample {
int frames_count; // Number of captured frames.
};
#ifdef ENABLE_LOGGING_AND_PROFILING
class Sampler {
public:
// Initialize sampler.