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

toJSON can cause stack overflow #16

Closed
AndreasMadsen opened this issue Sep 3, 2016 · 1 comment
Closed

toJSON can cause stack overflow #16

AndreasMadsen opened this issue Sep 3, 2016 · 1 comment
Labels

Comments

@AndreasMadsen
Copy link
Owner

Because toJSON works recursively dprof can reach a stack overflow. This could be fixed by flattening the format, such the root is a uid map and node.children is a uid list.

Root {
  version: String, // the version of dprof there generated this JSON file
  total: Number, // execution time in nanoseconds
  root: {
    Number(uid): Node, ...
  }
}

Node {
  name: String,      // Handle name of the async operation
  stack: [           // Contains the stack leading up to the async operation
    {
      description: String,
      filename: String,
      column: Number,
      line: Number
    }, ...
  ],
  init: Number,      // Timestamp for when the async operation is requested.
  before: [Number],  // Timestamp for when the callback is about to be called.
                     // This is an array because a callback may be called more
                     // than once.
  after: [Number],   // Timestamp for when the callback is finished.
                     // All timestamps are relative to the process startup time
                     // and the unit is nanoseconds.

  unrefed: Boolean,  // `true` if the handle will not keep the event loop open.

  children: [        // Shows async operations created in the callback
    uid, ...
  ]
}
@AndreasMadsen AndreasMadsen changed the title toJSON recusive issue toJSON can cause stack overflow Sep 3, 2016
This was referenced Sep 18, 2016
@AndreasMadsen
Copy link
Owner Author

It may be better to use a 2d array, such it easily can be transferred to and from a Map. (from: Array.from(items.entries()), to new Map(Root.root)).

Root {
  version: String, // the version of dprof there generated this JSON file
  total: Number, // execution time in nanoseconds
  root: [
    [Number(uid), Node],
    ...
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant