Commit 71f67d27 authored by Camillo's avatar Camillo Committed by V8 LUCI CQ

[log] Add more fine-grained logging flags

New Flags added:
--log-source-code
--log-source-position
--log-feedback-vector

With the above flags we can choose between detailed or lightweight
logging.

Drive-by-fix:
- Use std::isprint
- Add AppendRawString to avoid vprintf formatting for raw strings


Change-Id: I3e9eda8473153de9620d24617c5a5e12e2e3bd56
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3863469
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82897}
parent dd6233ab
......@@ -2069,12 +2069,16 @@ DEFINE_BOOL(log, false,
"Minimal logging (no API, code, GC, suspect, or handles samples).")
DEFINE_BOOL(log_all, false, "Log all events to the log file.")
DEFINE_BOOL(log_source_code, false, "Log source code.")
DEFINE_BOOL(log_source_position, false, "Log detailed source information.")
DEFINE_BOOL(log_code, false,
"Log code events to the log file without profiling.")
DEFINE_WEAK_IMPLICATION(log_code, log_source_code)
DEFINE_WEAK_IMPLICATION(log_code, log_source_position)
DEFINE_BOOL(log_feedback_vector, false, "Log FeedbackVectors on first creation")
DEFINE_BOOL(log_code_disassemble, false,
"Log all disassembled code to the log file.")
DEFINE_IMPLICATION(log_code_disassemble, log_code)
DEFINE_BOOL(log_source_code, false, "Log source code.")
DEFINE_BOOL(log_function_events, false,
"Log function events "
"(parse, compile, execute) separately.")
......
......@@ -129,6 +129,8 @@ void V8::Initialize() {
&FLAG_log_code,
&FLAG_log_code_disassemble,
&FLAG_log_source_code,
&FLAG_log_source_position,
&FLAG_log_feedback_vector,
&FLAG_log_function_events,
&FLAG_log_internal_timer_events,
&FLAG_log_deopt,
......
......@@ -171,19 +171,19 @@ void LogFile::MessageBuilder::AppendTwoByteCharacter(char c1, char c2) {
}
}
void LogFile::MessageBuilder::AppendCharacter(char c) {
if (c >= 32 && c <= 126) {
if (std::isprint(c)) {
if (c == ',') {
// Escape commas to avoid adding column separators.
AppendRawFormatString("\\x2C");
AppendRawString("\\x2C");
} else if (c == '\\') {
AppendRawFormatString("\\\\");
AppendRawString("\\\\");
} else {
// Safe, printable ascii character.
AppendRawCharacter(c);
}
} else if (c == '\n') {
// Escape newlines to avoid adding row separators.
AppendRawFormatString("\\n");
AppendRawString("\\n");
} else {
// Escape non-printable characters.
AppendRawFormatString("\\x%02x", c & 0xFF);
......@@ -242,6 +242,10 @@ void LogFile::MessageBuilder::AppendRawFormatString(const char* format, ...) {
}
}
void LogFile::MessageBuilder::AppendRawString(const char* str) {
log_->os_ << str;
}
void LogFile::MessageBuilder::AppendRawCharacter(char c) { log_->os_ << c; }
void LogFile::MessageBuilder::WriteToLogFile() { log_->os_ << std::endl; }
......
......@@ -95,6 +95,7 @@ class LogFile {
void AppendSymbolNameDetails(String str, bool show_impl_info);
void PRINTF_FORMAT(2, 3) AppendRawFormatString(const char* format, ...);
void AppendRawString(const char* format);
void AppendRawCharacter(const char character);
LogFile* log_;
......
......@@ -1287,6 +1287,7 @@ void V8FileLogger::LogSourceCodeInformation(Handle<AbstractCode> code,
Script script = Script::cast(script_object);
EnsureLogScriptSource(script);
if (!FLAG_log_source_position) return;
MSG_BUILDER();
msg << "code-source-info" << V8FileLogger::kNext
<< reinterpret_cast<void*>(code->InstructionStart(cage_base))
......@@ -1425,7 +1426,7 @@ void V8FileLogger::CodeCreateEvent(CodeTag tag, Handle<AbstractCode> code,
void V8FileLogger::FeedbackVectorEvent(FeedbackVector vector,
AbstractCode code) {
DisallowGarbageCollection no_gc;
if (!FLAG_log_code) return;
if (!FLAG_log_feedback_vector) return;
PtrComprCageBase cage_base(isolate_);
MSG_BUILDER();
msg << "feedback-vector" << kNext << Time();
......@@ -1755,6 +1756,7 @@ void V8FileLogger::ScriptDetails(Script script) {
}
bool V8FileLogger::EnsureLogScriptSource(Script script) {
if (!FLAG_log_source_code) return true;
// Make sure the script is written to the log file.
int script_id = script.id();
if (logged_source_code_.find(script_id) != logged_source_code_.end()) {
......
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