#ifndef COMPONENTS_SERVICES_HEAP_PROFILING_ALLOCATION_H_
#define COMPONENTS_SERVICES_HEAP_PROFILING_ALLOCATION_H_
#include <unordered_map>
#include <vector>
#include "components/services/heap_profiling/public/mojom/heap_profiling_client.mojom.h"
namespace heap_profiling {
using Address = uint64_t;
using mojom::AllocatorType;
struct AllocationSite {
AllocationSite(AllocatorType allocator,
std::vector<Address>&& stack,
int context_id);
AllocationSite(const AllocationSite&) = delete;
AllocationSite& operator=(const AllocationSite&) = delete;
~AllocationSite();
const AllocatorType allocator;
const std::vector<Address> stack;
const int context_id;
struct Hash {
size_t operator()(const AllocationSite& alloc) const { return alloc.hash_; }
};
private:
const size_t hash_;
};
inline bool operator==(const AllocationSite& a, const AllocationSite& b) {
return a.allocator == b.allocator && a.stack == b.stack &&
a.context_id == b.context_id;
}
struct AllocationMetrics {
size_t size = 0;
float count = 0;
};
using AllocationMap =
std::unordered_map<AllocationSite, AllocationMetrics, AllocationSite::Hash>;
}
#endif