jlfwong/chrome2calltree

Cannot read property 'hitCount' of undefined

abritinthebay opened this issue · 7 comments

Running against a Chrome profile (that works fine in Chrome) I get:

/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/index.js:9
    var result = node.hitCount;
                     ^

TypeError: Cannot read property 'hitCount' of undefined
    at totalHitCount (~/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/index.js:9:22)
    at calculateTimes (~/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/index.js:33:29)
    at Object.chromeProfileToCallgrind (~/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/index.js:66:5)
    at ~/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/bin/chrome2calltree.js:92:21
    at ReadStream.<anonymous> (~/.nvm/versions/node/v6.9.1/lib/node_modules/chrome2calltree/bin/chrome2calltree.js:68:9)
    at emitNone (events.js:91:20)
    at ReadStream.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Thoughts?

Hi @abritinthebay,

Nope! No idea.

If you figure it out, and submit a PR that fixes it (and preferably also a Chrome profile that shows what broke and what works now), I'm happy to review, merge, and released a new version.

Hello @jlfwong,
I've been having the same kind of error, as reported by @abritinthebay.
I've been debugging the code and it seems to me that our cpuprofile data is structured a bit differently, compared to what the methods in the index.js script expects.

For example:

  • functionName is not a property of node at the same level than selfHitCount, but it can be found within the child object node.callFrame.
  • There is no property called node.callUID, but there exists one called node.id, etc.

I'm not sure what is the reason behind this change. Maybe the Chrome version used to generate the profiles? (I was using Chrome 54.0.2840.98).

Anyway, just leaving this comment here in case someone wants to keep researching about it.

The CPU profile format has since changed quite a bit.

It will take a bit of work to adapt to the latest format, however it will probably make more sense to start parsing timeline trace files, as the DevTools will now be favoring them, even for JS profiling.

However, here's the latest details on the CPU profile format: https://groups.google.com/d/msgid/chrome-debugging-protocol/248b6e05-d954-41e2-a0d7-666f9a14c140%40googlegroups.com?utm_medium=email&utm_source=footer

Just commenting that at some point the Chrome profiler format changed, and NodeJS was still using the old cpuprofile format. However more recently NodeJS switched to using the new cpuprofile format, which this script no longer handles. Yes it will take a rewrite to get this code working with the new format.

On the upside, I can now load NodeJS .cpuprofile files into the latest version of Chrome which didn't use to be possible.

Does anyone know of any code which will convert the new .cpuprofile format to something that KCachegrind can use?

I don't maintain this repository any more in part because I don't use it. Instead, I import profiles into speedscope: https://github.com/jlfwong/speedscope.

There's code there that imports the .cpuprofile format and the Chrome timeline format: https://github.com/jlfwong/speedscope/blob/master/src/import/chrome.ts

It exports only to speedscope's own file format, but you're free to either re-use the code there to output to a different format, or make something which converts from speedscope's own file format to kcachegrind

The answer is not to use the native NodeJS profiler but instead to use the v8-profiler-next module found here: https://www.npmjs.com/package/v8-profiler-next -- this produces output in the older Chrome profiler format that can be converted to KCachegrind format using this script.

If you're waiting, I've fixed this in the latest commits from git.