Commit df7a027f authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

Factor out {CodeTracer} into a separate header file.

R=clemensh@chromium.org

Change-Id: Iab7210eaddb14c9ca8638cbc8d69206bbaf15462
Reviewed-on: https://chromium-review.googlesource.com/1134785Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54451}
parent f128acee
......@@ -1611,6 +1611,7 @@ v8_source_set("v8_base") {
"src/code-stubs-utils.h",
"src/code-stubs.cc",
"src/code-stubs.h",
"src/code-tracer.h",
"src/codegen.cc",
"src/codegen.h",
"src/collector.h",
......
......@@ -13,6 +13,7 @@
#include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/code-stubs-utils.h"
#include "src/code-tracer.h"
#include "src/counters.h"
#include "src/gdb-jit.h"
#include "src/heap/heap-inl.h"
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CODE_TRACER_H_
#define V8_CODE_TRACER_H_
#include "src/allocation.h"
#include "src/flags.h"
#include "src/globals.h"
#include "src/utils.h"
namespace v8 {
namespace internal {
class CodeTracer final : public Malloced {
public:
explicit CodeTracer(int isolate_id) : file_(nullptr), scope_depth_(0) {
if (!ShouldRedirect()) {
file_ = stdout;
return;
}
if (FLAG_redirect_code_traces_to == nullptr) {
SNPrintF(filename_, "code-%d-%d.asm", base::OS::GetCurrentProcessId(),
isolate_id);
} else {
StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length());
}
WriteChars(filename_.start(), "", 0, false);
}
class Scope {
public:
explicit Scope(CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); }
~Scope() { tracer_->CloseFile(); }
FILE* file() const { return tracer_->file(); }
private:
CodeTracer* tracer_;
};
void OpenFile() {
if (!ShouldRedirect()) {
return;
}
if (file_ == nullptr) {
file_ = base::OS::FOpen(filename_.start(), "ab");
}
scope_depth_++;
}
void CloseFile() {
if (!ShouldRedirect()) {
return;
}
if (--scope_depth_ == 0) {
fclose(file_);
file_ = nullptr;
}
}
FILE* file() const { return file_; }
private:
static bool ShouldRedirect() { return FLAG_redirect_code_traces; }
EmbeddedVector<char, 128> filename_;
FILE* file_;
int scope_depth_;
};
} // namespace internal
} // namespace v8
#endif // V8_CODE_TRACER_H_
......@@ -14,6 +14,7 @@
#include "src/base/optional.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/bootstrapper.h"
#include "src/code-tracer.h"
#include "src/compiler.h"
#include "src/compiler/basic-block-instrumentor.h"
#include "src/compiler/branch-elimination.h"
......
......@@ -11,6 +11,7 @@
#include "src/allocation.h"
#include "src/base/macros.h"
#include "src/boxed-float.h"
#include "src/code-tracer.h"
#include "src/deoptimize-reason.h"
#include "src/feedback-vector.h"
#include "src/frame-constants.h"
......
......@@ -1951,72 +1951,6 @@ class SafeForInterruptsScope : public InterruptsScope {
virtual ~SafeForInterruptsScope() = default;
};
class CodeTracer final : public Malloced {
public:
explicit CodeTracer(int isolate_id) : file_(nullptr), scope_depth_(0) {
if (!ShouldRedirect()) {
file_ = stdout;
return;
}
if (FLAG_redirect_code_traces_to == nullptr) {
SNPrintF(filename_,
"code-%d-%d.asm",
base::OS::GetCurrentProcessId(),
isolate_id);
} else {
StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length());
}
WriteChars(filename_.start(), "", 0, false);
}
class Scope {
public:
explicit Scope(CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); }
~Scope() { tracer_->CloseFile(); }
FILE* file() const { return tracer_->file(); }
private:
CodeTracer* tracer_;
};
void OpenFile() {
if (!ShouldRedirect()) {
return;
}
if (file_ == nullptr) {
file_ = base::OS::FOpen(filename_.start(), "ab");
}
scope_depth_++;
}
void CloseFile() {
if (!ShouldRedirect()) {
return;
}
if (--scope_depth_ == 0) {
fclose(file_);
file_ = nullptr;
}
}
FILE* file() const { return file_; }
private:
static bool ShouldRedirect() {
return FLAG_redirect_code_traces;
}
EmbeddedVector<char, 128> filename_;
FILE* file_;
int scope_depth_;
};
class StackTraceFailureMessage {
public:
explicit StackTraceFailureMessage(Isolate* isolate, void* ptr1 = nullptr,
......
......@@ -8,6 +8,7 @@
#include <vector>
#include "src/base/platform/platform.h"
#include "src/code-tracer.h"
#include "src/compilation-cache.h"
#include "src/elements.h"
#include "src/execution.h"
......
......@@ -7,6 +7,7 @@
#include "src/api.h"
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/code-tracer.h"
#include "src/heap/heap-inl.h"
#include "src/snapshot/builtin-deserializer.h"
#include "src/snapshot/snapshot.h"
......
......@@ -5,6 +5,7 @@
#include "src/snapshot/startup-serializer.h"
#include "src/api.h"
#include "src/code-tracer.h"
#include "src/global-handles.h"
#include "src/objects-inl.h"
#include "src/v8threads.h"
......
......@@ -5,6 +5,7 @@
#include "test/cctest/wasm/wasm-run-utils.h"
#include "src/assembler-inl.h"
#include "src/code-tracer.h"
#include "src/wasm/wasm-memory.h"
#include "src/wasm/wasm-objects-inl.h"
......
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