5 #ifndef V8_CODE_TRACER_H_ 6 #define V8_CODE_TRACER_H_ 8 #include "src/allocation.h" 10 #include "src/globals.h" 11 #include "src/utils.h" 18 explicit CodeTracer(
int isolate_id) : file_(
nullptr), scope_depth_(0) {
19 if (!ShouldRedirect()) {
24 if (FLAG_redirect_code_traces_to !=
nullptr) {
25 StrNCpy(filename_, FLAG_redirect_code_traces_to, filename_.length());
26 }
else if (isolate_id >= 0) {
27 SNPrintF(filename_,
"code-%d-%d.asm", base::OS::GetCurrentProcessId(),
30 SNPrintF(filename_,
"code-%d.asm", base::OS::GetCurrentProcessId());
33 WriteChars(filename_.start(),
"", 0,
false);
38 explicit Scope(
CodeTracer* tracer) : tracer_(tracer) { tracer->OpenFile(); }
39 ~
Scope() { tracer_->CloseFile(); }
41 FILE* file()
const {
return tracer_->file(); }
48 if (!ShouldRedirect()) {
52 if (file_ ==
nullptr) {
53 file_ = base::OS::FOpen(filename_.start(),
"ab");
60 if (!ShouldRedirect()) {
64 if (--scope_depth_ == 0) {
70 FILE* file()
const {
return file_; }
73 static bool ShouldRedirect() {
return FLAG_redirect_code_traces; }
75 EmbeddedVector<char, 128> filename_;
83 #endif // V8_CODE_TRACER_H_