Skip to content

Commit 24fb693

Browse files
committed
fixup! cli: implement --cpu-prof[-path]
1 parent aed11ed commit 24fb693

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/inspector_profiler.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,21 @@ void V8CpuProfilerConnection::OnMessage(
194194
return;
195195
}
196196
Isolate* isolate = env()->isolate();
197-
Local<Context> context = env()->context();
198197
HandleScope handle_scope(isolate);
198+
Local<Context> context = env()->context();
199199
Context::Scope context_scope(context);
200200
Local<String> result;
201201
if (!String::NewFromTwoByte(isolate,
202202
message.characters16(),
203203
NewStringType::kNormal,
204204
message.length())
205205
.ToLocal(&result)) {
206-
fprintf(stderr, "Failed to covert profiling message\n");
206+
fprintf(stderr, "Failed to convert profiling message\n");
207207
}
208208
WriteCpuProfile(result);
209209
}
210210

211-
bool V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
211+
void V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
212212
const std::string& path = env()->cpu_profile_path();
213213
CHECK(!path.empty());
214214
std::string directory = path.substr(0, path.find_last_of(kPathSeparator));
@@ -223,14 +223,13 @@ bool V8CpuProfilerConnection::WriteCpuProfile(Local<String> message) {
223223
"%s: Failed to create cpu profile directory %s\n",
224224
err_buf,
225225
directory.c_str());
226-
return false;
226+
return;
227227
}
228228
}
229229
MaybeLocal<String> result = GetResult(message);
230-
if (result.IsEmpty()) {
231-
return false;
230+
if (!result.IsEmpty()) {
231+
WriteResult(path.c_str(), result.ToLocalChecked());
232232
}
233-
return WriteResult(path.c_str(), result.ToLocalChecked());
234233
}
235234

236235
MaybeLocal<String> V8CpuProfilerConnection::GetResult(Local<String> message) {

src/inspector_profiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class V8CpuProfilerConnection : public V8ProfilerConnection {
7979
bool ending() const override { return ending_; }
8080

8181
private:
82-
bool WriteCpuProfile(v8::Local<v8::String> message);
82+
void WriteCpuProfile(v8::Local<v8::String> message);
8383
v8::MaybeLocal<v8::String> GetResult(v8::Local<v8::String> message);
8484

8585
std::unique_ptr<inspector::InspectorSession> session_;

test/sequential/test-cpu-prof.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,19 @@ function verifyFrames(output, file, suffix) {
3535
assert.notDeepStrictEqual(frames, []);
3636
}
3737

38+
let FIB = 30;
39+
// This is based on emperial values - in the CI, on Windows the program
40+
// tend to finish too fast then we won't be able to see the profiled script
41+
// in the samples, so we need to bump the values a bit. On slower platforms
42+
// like the Pis it could take more time to complete, we need to use a
43+
// smaller value so the test would not time out.
44+
if (common.isWindows) {
45+
FIB = 40;
46+
}
47+
3848
const env = {
3949
...process.env,
40-
FIB: 35,
50+
FIB,
4151
NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER'
4252
};
4353

0 commit comments

Comments
 (0)