Files
roytam1 14412dba88 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1200795, part 1 - Eliminate excessive detail from cycle collector graph memory reporting. r=njn (8775704ad4)
- Bug 1200795, part 2 - Add memory reporting for CCGraph::mPtrToNodeMap. r=njn (154912392e)
- Bug 1202670 - Move most of nsCycleCollector::RemoveObjectFromGraph into CCGraph. r=smaug (78b449602d)
- Bug 1163006, part 1 - Make the cycle collector use the concrete logger class. r=smaug (a23f4adfd3)
- Bug 1163657 - Clean up setting of mFlags in CCGraphBuilder's ctor. r=smaug (c49fa66d20)
- Bug 1163006, part 2 - Rename various cycle collector listener variables to logger. r=smaug (c655503d1b)
- Bug 1163006, part 3 - Clean up some cycle collector logger set up code. r=smaug (9825ec8e80)
- Bug 1163006, part 4 - De-COM the nsICycleCollectorListener methods we only call from C++. r=smaug (39e579782f)
- Bug 1163006, part 5 - Add a less COM-y getter for mWantAllTraces. r=smaug (70c424197e)
- Bug 1152505 - CCGraphBuilder::NoteChild should pass aEdgeName by reference. r=smaug (25ffabb54c)
- Bug 1189122 - Assert when we Suspect() when a CC scan is in progress. r=smaug (ae997c0fec)
- Bug 1189829 - fix quadratic behavior in nsConsoleService; r=erahm (2b37337085)
- Bug 1189231 - Impl operator->* to nsAutoPtr. r=nfroyd (a491e0e775)
- Bug 1196050 - Replace NSCAP_Zero usage with decltype(nullptr). r=froydnj (4b4d411103)
- Bug 1196925 - Remove the non-existing relocatable store buffer counts from about:memory; r=njn (d030d12a81)
- Bug 1123237 - Part 2. MemoryProfiler hooks in js engine. r=terrence (e3495c3520)
- Bug 1196847 - Part 1: Allow storage of a unique id for a cell independent of address; r=jonco (53b94846f1)
- Bug 1207730 - Update comments in Barrier.h and sort classes in same order; r=sfink (ba3abf54cb)
- Bug 1196847 - Part 2: Implement a cell hasher that uses unique id based hashes; r=jonco (3811c58b7a)
- Bug 1196848 - Add Zone::uniqueIds to about:memory reports; r=njn (bff35eb98c)
- Bug 1123237 - Part 3. Monitoring allocation and gc events in nursery and tenured heaps. r=terrence (47cc20bb98)
- Bug 1123237 - Part 4. Monitoring allocations and frees for ArrayBuffer. r=terrence,sfink (3495e46571)
- Bug 1123237 - Part 5. Don't emit inline allocation when memory profiler enabled. r=terrence (b4b44652d0)
- Bug 1123237 - Part 6. A new API to get backtrace without allocating memory in profiler. r=mstange (eff2d42cbd)
- Bug 1123237 - Part 7. XPCOM interface for memory profiler. r=smaug (f3a85f8181)
- Bug 1123237 - Part 8. Tracking the memory events. r=BenWa,terrence (8694fa4ad4)
- Bug 1123237 - Part 9. Interface to memory-profiler add-ons. r=jimb (1f8ed472ad)
- Bug 1123237 - Part 10. Expose SwapElements from nsBaseHashtable. r=nfroyd (a2e06425ad)
- Bug 1123237 - Part 11. Don't use STL in memory-profiler. r=BenWa,cervantes (c13096634c)
- Bug 1123237 - Part 12. Fix GC hazards. r=terrence (64776fc60e)
- Bug 1194424 - Part 0: Extend the core dump protobuf message format to accomodate allocation stacks; r=sfink (d25ca13aec)
- Bug 1167292 - Part 1: Add a telemetry probe to time how long it takes to save a heap snapshot; r=ejpbruel (25a9047d18)
- Bug 1167292 - Part 2: Add a telemetry probe to time how long it takes to read a heap snapshot; r=ejpbruel (71e3bb5fe3)
- Bug 1167292 - Part 3: Add telemetry probes for node and edge counts when saving heap snapshots; r=ejpbruel (7985b9edf6)
- Bug 1187062 - Part 0: Make js::Debugger::getObjectAllocationSite return a SavedFrame* rather than a JSObject*; r=sfink (0ec4175b9c)
- Bug 1204613 - Add a static_assert that ProfileEntry::{Flags,Category} do not overlap; r=djvj (a2d3672676)
- Bug 1204168 - Add the js::ProfileEntry::setCategory method; r=djvj (dce07b7eb4)
2022-01-17 09:17:44 +08:00

117 lines
2.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef memory_profiler_CompactTraceTable_h
#define memory_profiler_CompactTraceTable_h
#include "mozilla/HashFunctions.h"
#include "nsDataHashtable.h"
#include "nsTArray.h"
namespace mozilla {
struct TrieNode final
{
uint32_t parentIdx;
uint32_t nameIdx;
bool operator==(const TrieNode t) const
{
return parentIdx == t.parentIdx && nameIdx == t.nameIdx;
}
uint32_t Hash() const
{
return HashGeneric(parentIdx, nameIdx);
}
};
// This class maps a Node of type T to its parent's index in the
// map. When serializing, the map is traversed and put into an ordered
// array of Nodes.
template<typename KeyClass, typename T>
class NodeIndexMap final
{
public:
uint32_t Insert(const T& e)
{
uint32_t index = mMap.Count();
if (!mMap.Get(e, &index)) {
mMap.Put(e, index);
}
return index;
}
nsTArray<T> Serialize() const
{
nsTArray<T> v;
v.SetLength(mMap.Count());
for (auto iter = mMap.ConstIter(); !iter.Done(); iter.Next()) {
v[iter.Data()] = iter.Key();
}
return v;
}
uint32_t Size() const
{
return mMap.Count();
}
void Clear()
{
mMap.Clear();
}
private:
nsDataHashtable<KeyClass, uint32_t> mMap;
};
// Backtraces are stored in a trie to save spaces.
// Function names are stored in an unique table and TrieNodes contain indexes
// into that table.
// The trie is implemented with a hash table; children are stored in
// traces[TrieNode{parent node index, branch/function name index}].
class CompactTraceTable final
{
public:
CompactTraceTable()
{
mNames.Insert(nsAutoCString("(unknown)"));
mTraces.Insert(TrieNode{0, 0});
}
nsTArray<nsCString> GetNames() const
{
return mNames.Serialize();
}
nsTArray<TrieNode> GetTraces() const
{
return mTraces.Serialize();
}
// Returns an ID to a stacktrace.
uint32_t Insert(const nsTArray<nsCString>& aRawStacktrace)
{
uint32_t parent = 0;
for (auto& frame: aRawStacktrace) {
parent = mTraces.Insert(TrieNode{parent, mNames.Insert(frame)});
}
return parent;
}
void Reset()
{
mNames.Clear();
mTraces.Clear();
}
private:
NodeIndexMap<nsCStringHashKey, nsCString> mNames;
NodeIndexMap<nsGenericHashKey<TrieNode>, TrieNode> mTraces;
};
} // namespace mozilla
#endif // memory_profiler_CompactTraceTable_h