Skip to content

Commit e1b6917

Browse files
committed
feat: support grouping timing marks
1 parent 03ad57d commit e1b6917

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "boxednode",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "Create a shippable binary from a JS file",
55
"main": "lib/index.js",
66
"exports": {

resources/entry-point-trampoline.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ module.exports = (src, codeCacheMode, codeCache) => {
126126
jsTimingEntries = [];
127127
});
128128
}
129-
process.boxednode.markTime = (label) => {
130-
jsTimingEntries.push([label, process.hrtime.bigint()]);
129+
process.boxednode.markTime = (category, label) => {
130+
jsTimingEntries.push([category, label, process.hrtime.bigint()]);
131131
};
132132
process.boxednode.getTimingData = () => {
133133
if (isBuildingSnapshot()) {
@@ -136,9 +136,9 @@ module.exports = (src, codeCacheMode, codeCache) => {
136136
const data = [
137137
...jsTimingEntries,
138138
...process._linkedBinding('boxednode_linked_bindings').getTimingData()
139-
].sort((a, b) => Number(a[1] - b[1]));
139+
].sort((a, b) => Number(a[2] - b[2]));
140140
// Adjust times so that process initialization happens at time 0
141-
return data.map(([label, time]) => [label, Number(time - data[0][1])]);
141+
return data.map(([category, label, time]) => [category, label, Number(time - data[0][2])]);
142142
};
143143

144144
mainFunction(__filename, __dirname, require, exports, module);

resources/main-template.cc

+20-18
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ void TearDownOncePerProcess();
5353
namespace boxednode {
5454
namespace {
5555
struct TimingEntry {
56+
const char* const category;
5657
const char* const label;
5758
uint64_t const time;
5859
TimingEntry* next = nullptr;
5960
~TimingEntry() {
6061
delete next;
6162
}
6263
};
63-
TimingEntry start_time_entry { "Process initialization", uv_hrtime() };
64+
TimingEntry start_time_entry { "Node.js Instance", "Process initialization", uv_hrtime() };
6465
std::atomic<TimingEntry*> current_time_entry { &start_time_entry };
6566

66-
void MarkTime(const char* label) {
67-
TimingEntry* new_entry = new TimingEntry { label, uv_hrtime() };
67+
void MarkTime(const char* category, const char* label) {
68+
TimingEntry* new_entry = new TimingEntry {category, label, uv_hrtime() };
6869
do {
6970
new_entry->next = current_time_entry.load();
7071
} while(!current_time_entry.compare_exchange_strong(new_entry->next, new_entry));
@@ -81,6 +82,7 @@ void GetTimingData(const FunctionCallbackInfo<Value>& info) {
8182
std::vector<Local<Value>> entries;
8283
while (head != nullptr) {
8384
Local<Value> elements[] = {
85+
String::NewFromUtf8(isolate, head->category).ToLocalChecked(),
8486
String::NewFromUtf8(isolate, head->label).ToLocalChecked(),
8587
BigInt::NewFromUnsigned(isolate, head->time)
8688
};
@@ -143,15 +145,15 @@ static MaybeLocal<Value> LoadBoxednodeEnvironment(Local<Context> context) {
143145
String::NewFromUtf8Literal(isolate, BOXEDNODE_CODE_CACHE_MODE),
144146
boxednode::GetBoxednodeCodeCacheBuffer(isolate),
145147
};
146-
boxednode::MarkTime("Calling entrypoint");
148+
boxednode::MarkTime("Node.js Instance", "Calling entrypoint");
147149
if (entrypoint_ret.As<Function>()->Call(
148150
context,
149151
Null(isolate),
150152
sizeof(trampoline_args) / sizeof(trampoline_args[0]),
151153
trampoline_args).IsEmpty()) {
152154
return {}; // JS exception.
153155
}
154-
boxednode::MarkTime("Called entrypoint");
156+
boxednode::MarkTime("Node.js Instance", "Called entrypoint");
155157
return Null(isolate);
156158
}
157159
#endif
@@ -208,18 +210,18 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
208210
#else
209211
loop = uv_default_loop();
210212
#endif
211-
boxednode::MarkTime("Initialized Loop");
213+
boxednode::MarkTime("Node.js Instance", "Initialized Loop");
212214

213215
std::shared_ptr<ArrayBufferAllocator> allocator =
214216
ArrayBufferAllocator::Create();
215217

216218
#ifdef BOXEDNODE_CONSUME_SNAPSHOT
217219
std::vector<char> snapshot_blob_vec = boxednode::GetBoxednodeSnapshotBlobVector();
218-
boxednode::MarkTime("Decoded snapshot");
220+
boxednode::MarkTime("Node.js Instance", "Decoded snapshot");
219221
assert(EmbedderSnapshotData::CanUseCustomSnapshotPerIsolate());
220222
node::EmbedderSnapshotData::Pointer snapshot_blob =
221223
EmbedderSnapshotData::FromBlob(snapshot_blob_vec);
222-
boxednode::MarkTime("Read snapshot");
224+
boxednode::MarkTime("Node.js Instance", "Read snapshot");
223225
Isolate* isolate = NewIsolate(allocator, loop, platform, snapshot_blob.get());
224226
#elif NODE_VERSION_AT_LEAST(14, 0, 0)
225227
Isolate* isolate = NewIsolate(allocator, loop, platform);
@@ -230,7 +232,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
230232
fprintf(stderr, "%s: Failed to initialize V8 Isolate\n", args[0].c_str());
231233
return 1;
232234
}
233-
boxednode::MarkTime("Created Isolate");
235+
boxednode::MarkTime("Node.js Instance", "Created Isolate");
234236

235237
{
236238
Locker locker(isolate);
@@ -246,7 +248,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
246248
),
247249
node::FreeIsolateData);
248250

249-
boxednode::MarkTime("Created IsolateData");
251+
boxednode::MarkTime("Node.js Instance", "Created IsolateData");
250252
HandleScope handle_scope(isolate);
251253
Local<Context> context;
252254
#ifndef BOXEDNODE_CONSUME_SNAPSHOT
@@ -262,7 +264,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
262264
// node::LoadEnvironment() are being called.
263265
Context::Scope context_scope(context);
264266
#endif
265-
boxednode::MarkTime("Created Context");
267+
boxednode::MarkTime("Node.js Instance", "Created Context");
266268

267269
// Create a node::Environment instance that will later be released using
268270
// node::FreeEnvironment().
@@ -276,7 +278,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
276278
Context::Scope context_scope(context);
277279
#endif
278280
assert(isolate->InContext());
279-
boxednode::MarkTime("Created Environment");
281+
boxednode::MarkTime("Node.js Instance", "Created Environment");
280282

281283
const void* node_mod;
282284
const void* napi_mod;
@@ -297,7 +299,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
297299
env.get(),
298300
"boxednode_linked_bindings",
299301
boxednode::boxednode_linked_bindings_register, nullptr);
300-
boxednode::MarkTime("Added bindings");
302+
boxednode::MarkTime("Node.js Instance", "Added bindings");
301303

302304
// Set up the Node.js instance for execution, and run code inside of it.
303305
// There is also a variant that takes a callback and provides it with
@@ -311,7 +313,7 @@ static int RunNodeInstance(MultiIsolatePlatform* platform,
311313
if (LoadBoxednodeEnvironment(context).IsEmpty()) {
312314
return 1; // There has been a JS exception.
313315
}
314-
boxednode::MarkTime("Loaded Environment, entering loop");
316+
boxednode::MarkTime("Node.js Instance", "Loaded Environment, entering loop");
315317

316318
{
317319
// SealHandleScope protects against handle leaks from callbacks.
@@ -396,13 +398,13 @@ static int BoxednodeMain(std::vector<std::string> args) {
396398
if (args.size() > 1)
397399
args.insert(args.begin() + 1, "--openssl-shared-config");
398400
#endif
399-
boxednode::MarkTime("Start InitializeOncePerProcess");
401+
boxednode::MarkTime("Node.js Instance", "Start InitializeOncePerProcess");
400402
auto result = node::InitializeOncePerProcess(args, {
401403
node::ProcessInitializationFlags::kNoInitializeV8,
402404
node::ProcessInitializationFlags::kNoInitializeNodeV8Platform,
403405
node::ProcessInitializationFlags::kNoPrintHelpOrVersionOutput
404406
});
405-
boxednode::MarkTime("Finished InitializeOncePerProcess");
407+
boxednode::MarkTime("Node.js Instance", "Finished InitializeOncePerProcess");
406408
for (const std::string& error : result->errors())
407409
fprintf(stderr, "%s: %s\n", args[0].c_str(), error.c_str());
408410
if (result->exit_code() != 0) {
@@ -427,7 +429,7 @@ static int BoxednodeMain(std::vector<std::string> args) {
427429
V8::InitializePlatform(platform.get());
428430
V8::Initialize();
429431

430-
boxednode::MarkTime("Initialized V8");
432+
boxednode::MarkTime("Node.js Instance", "Initialized V8");
431433
// See below for the contents of this function.
432434
int ret = RunNodeInstance(platform.get(), args, exec_args);
433435

@@ -476,7 +478,7 @@ int wmain(int argc, wchar_t* wargv[]) {
476478
int main(int argc, char** argv) {
477479
argv = uv_setup_args(argc, argv);
478480
std::vector<std::string> args(argv, argv + argc);
479-
boxednode::MarkTime("Enter BoxednodeMain");
481+
boxednode::MarkTime("Node.js Instance", "Enter BoxednodeMain");
480482
return BoxednodeMain(std::move(args));
481483
}
482484
#endif

0 commit comments

Comments
 (0)