Skip to content

Commit

Permalink
fixup! cli: implement --cpu-prof[-path]
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Apr 10, 2019
1 parent aed11ed commit 24fb693
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/inspector_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ void V8CpuProfilerConnection::OnMessage(
return;
}
Isolate* isolate = env()->isolate();
Local<Context> context = env()->context();
HandleScope handle_scope(isolate);
Local<Context> context = env()->context();
Context::Scope context_scope(context);
Local<String> result;
if (!String::NewFromTwoByte(isolate,
message.characters16(),
NewStringType::kNormal,
message.length())
.ToLocal(&result)) {
fprintf(stderr, "Failed to covert profiling message\n");
fprintf(stderr, "Failed to convert profiling message\n");
}
WriteCpuProfile(result);
}

bool V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
void V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
const std::string& path = env()->cpu_profile_path();
CHECK(!path.empty());
std::string directory = path.substr(0, path.find_last_of(kPathSeparator));
Expand All @@ -223,14 +223,13 @@ bool V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
"%s: Failed to create cpu profile directory %s\n",
err_buf,
directory.c_str());
return false;
return;
}
}
MaybeLocal<String> result = GetResult(message);
if (result.IsEmpty()) {
return false;
if (!result.IsEmpty()) {
WriteResult(path.c_str(), result.ToLocalChecked());
}
return WriteResult(path.c_str(), result.ToLocalChecked());
}

MaybeLocal<String> V8CpuProfilerConnection::GetResult(Local<String> message) {
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class V8CpuProfilerConnection : public V8ProfilerConnection {
bool ending() const override { return ending_; }

private:
bool WriteCpuProfile(v8::Local<v8::String> message);
void WriteCpuProfile(v8::Local<v8::String> message);
v8::MaybeLocal<v8::String> GetResult(v8::Local<v8::String> message);

std::unique_ptr<inspector::InspectorSession> session_;
Expand Down
12 changes: 11 additions & 1 deletion test/sequential/test-cpu-prof.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,19 @@ function verifyFrames(output, file, suffix) {
assert.notDeepStrictEqual(frames, []);
}

let FIB = 30;
// This is based on emperial values - in the CI, on Windows the program
// tend to finish too fast then we won't be able to see the profiled script
// in the samples, so we need to bump the values a bit. On slower platforms
// like the Pis it could take more time to complete, we need to use a
// smaller value so the test would not time out.
if (common.isWindows) {
FIB = 40;
}

const env = {
...process.env,
FIB: 35,
FIB,
NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER'
};

Expand Down

0 comments on commit 24fb693

Please sign in to comment.