On Wed, Dec 9, 2015 at 8:55 PM, Jane Chen <
jxch...@gmail.com> 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.