#include "src/trace_processor/importers/proto/heap_graph_tracker.h"
#include <algorithm>
#include <array>
#include <cinttypes>
#include <cstdint>
#include <cstring>
#include <deque>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "perfetto/base/logging.h"
#include "perfetto/ext/base/string_view.h"
#include "protos/perfetto/trace/profiling/heap_graph.pbzero.h"
#include "src/trace_processor/storage/stats.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/tables/profiler_tables_py.h"
#include "src/trace_processor/util/profiler_util.h"
namespace perfetto::trace_processor {
namespace {
ClassTable;
ObjectTable;
ReferenceTable;
template <typename F>
void ForReferenceSet(TraceStorage* storage,
ObjectTable::ConstRowReference object,
F fn) { … }
struct ClassDescriptor { … };
ClassDescriptor GetClassDescriptor(const TraceStorage& storage,
ObjectTable::Id obj_id) { … }
std::optional<ObjectTable::Id> GetReferredObj(const TraceStorage& storage,
uint32_t ref_set_id,
const std::string& field_name) { … }
std::map<ClassDescriptor, ClassDescriptor>
BuildSuperclassMap(UniquePid upid, int64_t ts, TraceStorage* storage) { … }
int64_t GetSizeFromNativeAllocationRegistry(int64_t nar_size) { … }
constexpr std::array<protos::pbzero::HeapGraphRoot::Type, 3>
kRootTypePrecedence = …;
}
std::optional<base::StringView> GetStaticClassTypeName(base::StringView type) { … }
size_t NumberOfArrays(base::StringView type) { … }
NormalizedType GetNormalizedType(base::StringView type) { … }
base::StringView NormalizeTypeName(base::StringView type) { … }
std::string DenormalizeTypeName(NormalizedType normalized,
base::StringView deobfuscated_type_name) { … }
HeapGraphTracker::HeapGraphTracker(TraceStorage* storage)
: … { … }
HeapGraphTracker::SequenceState& HeapGraphTracker::GetOrCreateSequence(
uint32_t seq_id) { … }
bool HeapGraphTracker::SetPidAndTimestamp(SequenceState* sequence_state,
UniquePid upid,
int64_t ts) { … }
ObjectTable::RowReference HeapGraphTracker::GetOrInsertObject(
SequenceState* sequence_state,
uint64_t object_id) { … }
ClassTable::RowReference HeapGraphTracker::GetOrInsertType(
SequenceState* sequence_state,
uint64_t type_id) { … }
void HeapGraphTracker::AddObject(uint32_t seq_id,
UniquePid upid,
int64_t ts,
SourceObject obj) { … }
void HeapGraphTracker::AddRoot(uint32_t seq_id,
UniquePid upid,
int64_t ts,
SourceRoot root) { … }
void HeapGraphTracker::AddInternedLocationName(uint32_t seq_id,
uint64_t intern_id,
StringId strid) { … }
void HeapGraphTracker::AddInternedType(
uint32_t seq_id,
uint64_t intern_id,
StringId strid,
std::optional<uint64_t> location_id,
uint64_t object_size,
std::vector<uint64_t> field_name_ids,
uint64_t superclass_id,
uint64_t classloader_id,
bool no_fields,
protos::pbzero::HeapGraphType::Kind kind) { … }
void HeapGraphTracker::AddInternedFieldName(uint32_t seq_id,
uint64_t intern_id,
base::StringView str) { … }
void HeapGraphTracker::SetPacketIndex(uint32_t seq_id, uint64_t index) { … }
HeapGraphTracker::InternedType* HeapGraphTracker::GetSuperClass(
SequenceState* sequence_state,
const InternedType* current_type) { … }
void HeapGraphTracker::FinalizeProfile(uint32_t seq_id) { … }
std::optional<ObjectTable::Id> HeapGraphTracker::GetReferenceByFieldName(
ObjectTable::Id obj,
StringId field) { … }
void HeapGraphTracker::PopulateNativeSize(const SequenceState& seq) { … }
void HeapGraphTracker::PopulateSuperClasses(const SequenceState& seq) { … }
void HeapGraphTracker::GetChildren(ObjectTable::RowReference object,
std::vector<ObjectTable::Id>& children) { … }
size_t HeapGraphTracker::RankRoot(StringId type) { … }
void HeapGraphTracker::MarkRoot(ObjectTable::RowReference row_ref,
StringId type) { … }
void HeapGraphTracker::UpdateShortestPaths(ObjectTable::RowReference row_ref) { … }
void HeapGraphTracker::FindPathFromRoot(ObjectTable::RowReference row_ref,
PathFromRoot* path) { … }
std::unique_ptr<tables::ExperimentalFlamegraphTable>
HeapGraphTracker::BuildFlamegraph(const int64_t current_ts,
const UniquePid current_upid) { … }
void HeapGraphTracker::FinalizeAllProfiles() { … }
bool HeapGraphTracker::IsTruncated(UniquePid upid, int64_t ts) { … }
StringId HeapGraphTracker::InternRootTypeString(
protos::pbzero::HeapGraphRoot::Type root_type) { … }
StringId HeapGraphTracker::InternTypeKindString(
protos::pbzero::HeapGraphType::Kind kind) { … }
HeapGraphTracker::~HeapGraphTracker() = default;
}