Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect source file names in time profiles in Node 8 #89

Closed
nolanmar511 opened this issue Dec 9, 2017 · 25 comments
Closed

Incorrect source file names in time profiles in Node 8 #89

nolanmar511 opened this issue Dec 9, 2017 · 25 comments
Assignees
Labels
api: cloudprofiler Issues related to the googleapis/cloud-profiler-nodejs API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@nolanmar511
Copy link
Contributor

nolanmar511 commented Dec 9, 2017

For the sample application, a time profile indicated that the function 'fill' was located within the source file below, when it should be marked as within 'buffer.js'. This is likely a problem with serialization, and since much of the serialization code is shared, heap profiles may also be impacted.

const profiler = require('@google-cloud/profiler')

let count = 0;
function additionFunction() {
    let a = 0
          for (var i = 0; i < 10000; i++) {
                a = a + 3;
                a = a * a;
                a = Math.sqrt(a);
                  }
      setImmediate(additionFunction);
}

function fillBuffer() {
    var buffer = new Buffer(500);
    for (var k = 0; k < 1e2; k++)
      buffer.fill(0);
    setImmediate(fillBuffer);
}

profiler.start({
    projectId: 'nolanmar-testappstandard',
      logLevel: 5,
        serviceContext: {
              service: 'app-std',
                  version: '0'
                        },
});

additionFunction();
fillBuffer();
@nolanmar511 nolanmar511 changed the title Fix file names in profile entries Incorrect source file names in profiles Dec 9, 2017
@nolanmar511 nolanmar511 changed the title Incorrect source file names in profiles Incorrect source file names in time profiles Dec 9, 2017
@nolanmar511
Copy link
Contributor Author

nolanmar511 commented Dec 11, 2017

I'm less certain that this is a problem with serialization.
I printed out the profile prior to serialization and saw this as part of the profile:

{
                    "name": "fillBuffer",
                    "scriptName": "/path/to/server.js",
                    "scriptId": 71,
                    "lineNumber": 15,
                    "columnNumber": 20,
                    "hitCount": 50,
                    "children": [
                      {
                        "name": "fill",
                        "scriptName": "/path/to/server.js",
                        "scriptId": 24,
                        "lineNumber": 0,
                        "columnNumber": 0,
                        "hitCount": 129,
                        "children": [
                          {
                            "name": "fill",
                            "scriptName": "",
                            "scriptId": 0,
                            "lineNumber": 0,
                            "columnNumber": 0,
                            "hitCount": 501,
                            "children": []
                          }
                        ]
                      },
...

The function 'fill' is listed as having server.js as the file it is in.

@nolanmar511 nolanmar511 changed the title Incorrect source file names in time profiles Incorrect source file names in time profiles in Node 8 Dec 12, 2017
@nolanmar511
Copy link
Contributor Author

nolanmar511 commented Dec 12, 2017

Ran with Node 6, saw this in the profile before serialization:

{
    "name": "fillBuffer",
    "scriptName": "/path/to/server.js",
    "scriptId": 61,
    "lineNumber": 15,
    "columnNumber": 20,
    "hitCount": 90,
    "children": [
      {
        "name": "fill",
        "scriptName": "buffer.js",
        "scriptId": 38,
        "lineNumber": 662,
        "columnNumber": 38,
        "hitCount": 243,
        "children": [
          {
            "name": "fill",
            "scriptName": "",
            "scriptId": 0,
            "lineNumber": 0,
            "columnNumber": 0,
            "hitCount": 481,
            "children": []
          }
        ]
      },

@nolanmar511
Copy link
Contributor Author

nolanmar511 commented Dec 12, 2017

Buffer seems to have the correct source file with node 8, though, and the wrong source file with node 6.

With node 6:

{
                        "name": "Buffer",
                        "scriptName": "/path/to/server.js",
                        "scriptId": 38,
                        "lineNumber": 0,
                        "columnNumber": 0,
                        "hitCount": 0,
                        "children": [

With Node 8:

{
                        "name": "Buffer",
                        "scriptName": "buffer.js",
                        "scriptId": 24,
                        "lineNumber": 147,
                        "columnNumber": 16,
                        "hitCount": 2,
                        "children": [

@aalexand
Copy link
Contributor

Just to clarify, are you looking at the fill() branch or Buffer() constructor branch? Your previous comments talk about fill() but the last one seems to talk about Buffer()? Just want to make sure we keep looking at the same data.

od4ytmwf8wm

@nolanmar511
Copy link
Contributor Author

Yes, I am talking about that section of the flame chart.
In node 6, the filename for fill is Buffer.js, and the filename for Buffer is /path/to/server.js.
In node 8, the filename for fill is path/to/server.js, and the filename for Buffer is Buffer.js.

So basically, both node 6 and node 8 seem to have problems with the filenames in the profiles, but the problems are different.

@aalexand
Copy link
Contributor

aalexand commented Dec 12, 2017 via email

@ofrobots
Copy link
Contributor

I think it is quite likely due to inlining. /cc @bmeurer @hashseed

@bmeurer
Copy link

bmeurer commented Dec 12, 2017

If you're essentially using --prof then it's very likely that this is due to inlining, yes.

@ofrobots
Copy link
Contributor

This uses the CPU Profiler (cpu-profiler.h) which is based on timer based statistical sampling. I think that's what prof does as well.

I think https://crbug.com/v8/6239 is supposed to be the tracking bug for this issue in V8.

@bmeurer
Copy link

bmeurer commented Dec 13, 2017

That tracking bug was about something else. I created v8:7203 for this specifically now.

@aalexand
Copy link
Contributor

As a workaround on the profiler side I guess we could pretend the source file is empty when the line number is zero. But I'd rather prefer the profiler do that for us (or put the right source file name).

@nolanmar511
Copy link
Contributor Author

@hashseed -- we'd mentioned this problem earlier.
Is this behavior expected? Can it be fixed?

@bmeurer
Copy link

bmeurer commented Dec 14, 2017

@nolanmar511 Yes. We'll be working on supporting that as well.

@aalexand
Copy link
Contributor

@nolanmar511 @bmeurer @hashseed Who should own this issue?

@hashseed
Copy link

@fhinkel do you want to take a look?

@fhinkel
Copy link
Contributor

fhinkel commented Dec 20, 2017

Yes, I'll check

@fhinkel
Copy link
Contributor

fhinkel commented Dec 21, 2017

Is there an easy way to run this locally? I don't have auth credentials for GCP.

Using the --inspect flag, DevTools shows buffer.js as source for both fill and Buffer (for Node 6 and Node 8). There's a second fill, not attributed to any file, I'm assuming that's because it was inlined. Is that maybe misattributed in @google-cloud/profiler?

screenshot from 2017-12-21 14 26 24

Edit: The recorded profile changes once I kill the Node process: and a bunch of file attributions change to server.js. (Start recording, stop recording, see correct buffer.js, stop Node, DevTools automatically disconnects, server.js attributions change to buffer.js attributions

Gist, just run node --inspect server.js.

@aalexand
Copy link
Contributor

aalexand commented Dec 21, 2017 via email

@nolanmar511
Copy link
Contributor Author

@fhinkel -- PR #95 will make it so that profiles are written out when starting the profile with .startLocal(). So, you can replace .start() with .startLocal(), if you get the code from that PR.

To see profiles before they are serialized, you can add console.log(result) after this line. The only processing done to result between the call to the profile and this point happens in this file.
I don't know that this code uses the same profiler which is used by inspect.

@fhinkel
Copy link
Contributor

fhinkel commented Dec 29, 2017

Here's my V8 patch that fixes the wrong file attribution for the cloud profiler and DevTools. We can probably backport it to Node master (and later to 8) after a few days of Canary coverage.

kisg pushed a commit to paul99/v8mips that referenced this issue Jan 2, 2018
Use the script name from the shared function info to create an
inline entry. Otherwise functions are attributed to the wrong file
in the CpuProfileNode.

See googleapis/cloud-profiler-nodejs#89


Bug: v8:7203, v8:7241
Change-Id: I7a7524ad68a295efd35ef94295cd48f823376e07
Reviewed-on: https://chromium-review.googlesource.com/845624
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50324}
kisg pushed a commit to paul99/v8mips that referenced this issue Jan 2, 2018
This reverts commit c500aa9.

Reason for revert: Breaks V8 Linux64 - gyp

Original change's description:
> [cpu-profiler] Fix script name when recording inlining info
> 
> Use the script name from the shared function info to create an
> inline entry. Otherwise functions are attributed to the wrong file
> in the CpuProfileNode.
> 
> See googleapis/cloud-profiler-nodejs#89
> 
> 
> Bug: v8:7203, v8:7241
> Change-Id: I7a7524ad68a295efd35ef94295cd48f823376e07
> Reviewed-on: https://chromium-review.googlesource.com/845624
> Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
> Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#50324}

TBR=jarin@chromium.org,franzih@chromium.org

Change-Id: I5876d24723bb6bd20854db91a579485b07313a69
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7203, v8:7241
Reviewed-on: https://chromium-review.googlesource.com/846771
Reviewed-by: Franziska Hinkelmann <franzih@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50325}
kisg pushed a commit to paul99/v8mips that referenced this issue Jan 3, 2018
Use the script name from the shared function info to create an
inline entry. Otherwise functions are attributed to the wrong file
in the CpuProfileNode.

See googleapis/cloud-profiler-nodejs#89

Bug: v8:7203, v8:7241
Change-Id: I8ea31943741770e6611275a9c93375922b934547
Reviewed-on: https://chromium-review.googlesource.com/848093
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50339}
@aalexand
Copy link
Contributor

aalexand commented Jan 9, 2018

@nolanmar511 assigned to you for the verification.

@fhinkel
Copy link
Contributor

fhinkel commented Jan 15, 2018

Merged to 6.4, should get picked up in this PR and land in Node master on January 23rd.

@ofrobots
Copy link
Contributor

Opened back port PR for current version of V8 in Node: nodejs/node#18298. Even if 6.4 gets merged before my PR, this is needed in older versions of node.

ofrobots added a commit to ofrobots/node that referenced this issue Jan 24, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{nodejs#50339}

Refs: v8/v8@76c3ac5
PR-URL: nodejs#18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@aalexand
Copy link
Contributor

@nolanmar511 Please verify that this is fixed and close issue if so.

@nolanmar511
Copy link
Contributor Author

This seems fixed.
I ran the script in description of this issue with node 8, inspected the flame graph of a profile and saw this:
without_fix
The fill() function is attributed to the script from which it is called.

I then installed the nightly release from today (2-13-18), and ran with that release. The flame graph correctly attributed the fill() function to buffer.js
with_fix

MylesBorins pushed a commit to nodejs/node that referenced this issue Feb 21, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#50339}

Refs: v8/v8@76c3ac5
PR-URL: #18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit to nodejs/node that referenced this issue Feb 21, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#50339}

Refs: v8/v8@76c3ac5
PR-URL: #18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit to nodejs/node that referenced this issue Feb 21, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#50339}

Refs: v8/v8@76c3ac5
PR-URL: #18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit to nodejs/node that referenced this issue Apr 13, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{#50339}

Refs: v8/v8@76c3ac5
PR-URL: #18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
This fixes a bug in the CPU profiler where some ticks were attributed
to the wrong file.

Original commit message:
  [cpu-profiler] Fix script name when recording inlining info

  Use the script name from the shared function info to create an
  inline entry. Otherwise functions are attributed to the wrong file
  in the CpuProfileNode.

  See googleapis/cloud-profiler-nodejs#89

  Bug: v8:7203, v8:7241
  Change-Id: I8ea31943741770e6611275a9c93375922b934547
  Reviewed-on: https://chromium-review.googlesource.com/848093
  Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
  Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
  Cr-Commit-Position: refs/heads/master@{nodejs#50339}

Refs: v8/v8@76c3ac5
PR-URL: nodejs#18298
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@google-cloud-label-sync google-cloud-label-sync bot added the api: cloudprofiler Issues related to the googleapis/cloud-profiler-nodejs API. label Jan 31, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudprofiler Issues related to the googleapis/cloud-profiler-nodejs API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

7 participants