On Wed, Dec 9, 2015 at 8:55 PM, Jane Chen <[email protected]> wrote:
> So you mean the integers in the samples array are indexes of
> CpuProfileNodes?  But does CpuProfileNode have an index?  Still struggling
> to see how to get the integers in the samples array.

You can map them to numeric indexes like this:

  int monotonic_counter = 0;
  std::map<const v8::CpuProfileNode*, int> nodes;
  std::vector<int> samples;
  for (int i = 0; i < profile->GetSamplesCount(); i += 1) {
    int& sample = nodes[profile->GetSample(i)];
    if (sample == 0) sample = ++monotonic_counter;
    samples.push_back(sample);
  }
  // now write out |samples|

If you use an appropriately sized hash table instead of a map you can
bring algorithm complexity down from O(n*lg n) to amortized O(n).
Hope that helps.

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to