MCPcopy Index your code
hub / github.com/nodejs/node / debugWithTimer

Function debugWithTimer

lib/internal/util/debuglog.js:358–520  ·  view source on GitHub ↗

* Debuglog with time fns and support for trace * @param {string} set * @param {(startTimer: TimerStart, endTimer: TimerEnd, logTimer: TimerLog) => void} cb * @returns {{startTimer: TimerStart, endTimer: TimerEnd, logTimer: TimerLog}}

(set, cb)

Source from the content-addressed store, hash-verified

356 * @returns {{startTimer: TimerStart, endTimer: TimerEnd, logTimer: TimerLog}}
357 */
358function debugWithTimer(set, cb) {
359 set = StringPrototypeToUpperCase(set);
360
361 if (tracesStores === undefined) {
362 tracesStores = { __proto__: null };
363 }
364
365 /**
366 * @type {LogImpl}
367 */
368 function logImpl(label, timeFormatted, args) {
369 const pid = process.pid;
370 const colors = { colors: lazyUtilColors().shouldColorize(process.stderr) };
371 const coloredPID = inspect(pid, colors);
372
373 if (args === undefined)
374 process.stderr.write(format('%s %s %s: %s\n', set, coloredPID, label, timeFormatted));
375 else
376 process.stderr.write(
377 format(
378 '%s %s %s: %s\n',
379 set,
380 coloredPID,
381 label,
382 timeFormatted,
383 ...new SafeArrayIterator(args),
384 ),
385 );
386 }
387
388 const traceCategory = `node,node.${StringPrototypeToLowerCase(set)}`;
389 let traceCategoryBuffer;
390 let debugLogCategoryEnabled = false;
391 let timerFlags = kNone;
392
393 function ensureTimerFlagsAreUpdated() {
394 timerFlags &= ~kSkipTrace;
395
396 if (traceCategoryBuffer[0] === 0) {
397 timerFlags |= kSkipTrace;
398 }
399 }
400
401 /**
402 * @type {TimerStart}
403 */
404 function internalStartTimer(logLabel, traceLabel) {
405 ensureTimerFlagsAreUpdated();
406
407 if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) {
408 return;
409 }
410
411 time(
412 tracesStores[set],
413 traceCategory,
414 'debuglog.time',
415 timerFlags,

Callers 1

loader.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…