chromium/components/services/heap_profiling/json_exporter.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/services/heap_profiling/json_exporter.h"

#include <inttypes.h>

#include <map>
#include <unordered_map>

#include "base/containers/adapters.h"
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/traced_value.h"
#include "base/values.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/tracing_observer_traced_value.h"

namespace heap_profiling {
namespace {

// Maps strings to integers for the JSON string table.
StringTable;

// Maps allocation site to node_id of the top frame.
AllocationToNodeId;

constexpr int kAllocatorCount =;

struct BacktraceNode {};

BacktraceTable;

// The hardcoded ID for having no context for an allocation.
constexpr int kUnknownTypeId =;

const char* StringForAllocatorType(uint32_t type) {}

// Writes the top-level allocators section. This section is used by the tracing
// UI to show a small summary for each allocator. It's necessary as a
// placeholder to allow the stack-viewing UI to be shown.
base::Value::Dict BuildAllocatorsSummary(const AllocationMap& allocations) {}

base::Value BuildMemoryMaps(const ExportParams& params) {}

// Inserts or retrieves the ID for a string in the string table.
int AddOrGetString(const std::string& str,
                   StringTable* string_table,
                   ExportParams* params) {}

// Processes the context information.
// Strings are added for each referenced context and a mapping between
// context IDs and string IDs is filled in for each.
void FillContextStrings(ExportParams* params,
                        StringTable* string_table,
                        std::map<int, int>* context_to_string_id_map) {}

int AddOrGetBacktraceNode(BacktraceNode node,
                          BacktraceTable* backtrace_table,
                          ExportParams* params) {}

// Returns the index into nodes of the node to reference for this stack. That
// node will reference its parent node, etc. to allow the full stack to
// be represented.
int AppendBacktraceStrings(const AllocationSite& alloc,
                           BacktraceTable* backtrace_table,
                           StringTable* string_table,
                           ExportParams* params) {}

base::Value::List BuildStrings(const StringTable& string_table) {}

base::Value::List BuildMapNodes(const BacktraceTable& nodes) {}

base::Value::List BuildTypeNodes(const std::map<int, int>& type_to_string) {}

base::Value::Dict BuildAllocations(const AllocationMap& allocations,
                                   const AllocationToNodeId& alloc_to_node_id) {}

}  // namespace

ExportParams::ExportParams() = default;
ExportParams::~ExportParams() = default;

std::string ExportMemoryMapsAndV2StackTraceToJSON(ExportParams* params) {}

}  // namespace heap_profiling