cloud-profiler-nodejs icon indicating copy to clipboard operation
cloud-profiler-nodejs copied to clipboard

setTimeout is attributed to the file in which it is called.

Open nolanmar511 opened this issue 7 years ago • 3 comments

image

This is the script used (it's what we use in our prober), but I saw the same thing happening when I was experimenting with getting accurate line numbers:

var profiler = require('@google-cloud/profiler').start({
  serviceContext: {
    service: 'service',
    version: 'version',
  },
});
const startTime = Date.now();
const testArr = [];

function nodeJSLoop(durationSeconds) {
  for (let i = 0; i < testArr.length; i++) {
    for (let j = 0; j < testArr[i].length; j++) {
      testArr[i][j] = Math.sqrt(j * testArr[i][j]);
    }
  }
  if (Date.now() - startTime < 1000 * durationSeconds) {
    setTimeout(() => nodeJSLoop(durationSeconds), 5);
  }
}

function nodeJSBench(durationSeconds) {
  // Allocate 16 MiB in 64 KiB chunks.
  for (let i = 0; i < 16*16; i++) {
    testArr[i] = new Array(64 * 1024);
  }
	nodeJSLoop(durationSeconds)
}

nolanmar511 avatar Nov 29 '18 18:11 nolanmar511

@psmarshall -- is this be expected?

nolanmar511 avatar Nov 29 '18 22:11 nolanmar511

Is the expected result that it shows up in node/lib/timers.js where this is implemented?

psmarshall avatar Dec 04 '18 12:12 psmarshall

Yes, I think I would expect it's file to be timer.js (it's parent is indicated as being in "timer.js"). Should have clarified, so thanks!

nolanmar511 avatar Dec 04 '18 14:12 nolanmar511