From 148c34d84201cdbe16d49c605d6d52e7fecd33aa Mon Sep 17 00:00:00 2001 From: Giorgi Lomia Date: Fri, 8 Oct 2021 19:05:37 +0000 Subject: [PATCH] Cleanup in progress. --- tools/graph-stats/graph-memory-stats.cpp | 82 ++++++++++-------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/tools/graph-stats/graph-memory-stats.cpp b/tools/graph-stats/graph-memory-stats.cpp index d5ac837771..53faaf8b34 100644 --- a/tools/graph-stats/graph-memory-stats.cpp +++ b/tools/graph-stats/graph-memory-stats.cpp @@ -39,10 +39,10 @@ static cll::opt inputfilename( static cll::opt outputfilename( cll::Positional, cll::desc("out-file"), cll::Required); -using map_element = std::unordered_map; -using map_string_element = std::unordered_map; -using memory_map = std::unordered_map< - std::string, std::variant>; +using MemoryUsageMap = std::unordered_map; +using TypeInformationMap = std::unordered_map; +using FullReportMap = std::unordered_map< + std::string, std::variant>; struct Visitor : public katana::ArrowVisitor { using ResultType = katana::Result>; @@ -95,20 +95,11 @@ PrintAtomicTypes(const std::vector& atomic_types) { } } -template -void -PrintMapping(const std::shared_ptr u) { - for (const auto& n : u) { - fmt::print("{} : {}\n", n->first, n->second); - } -} - std::pair RunVisit( const std::shared_ptr scalars, const std::string name, - const std::shared_ptr allocations, - const std::shared_ptr usage, int64_t* total_alloc, - int64_t* total_usage) { + MemoryUsageMap* allocations, MemoryUsageMap* usage, int64_t& total_alloc, + int64_t& total_usage) { Visitor v; arrow::Array* arr = scalars.get(); auto res = katana::VisitArrow(v, *arr); @@ -157,9 +148,8 @@ void GatherMemoryAllocation( const std::shared_ptr schema, const std::unique_ptr& g, - std::shared_ptr allocations, - std::shared_ptr usage, std::shared_ptr width, - std::shared_ptr types, bool node_or_edge) { + MemoryUsageMap* allocations, MemoryUsageMap* usage, MemoryUsageMap* width, + TypeInformationMap* types, bool node_or_edge) { std::shared_ptr prop_field; int64_t total_alloc = 0; int64_t total_usage = 0; @@ -174,7 +164,7 @@ GatherMemoryAllocation( } auto bit_width = arrow::bit_width(dtype->id()); auto mem_allocations = RunVisit( - prop_field, prop_name, allocations, usage, &total_alloc, &total_usage); + prop_field, prop_name, allocations, usage, total_alloc, total_usage); width->insert(std::pair(prop_name, bit_width)); types->insert(std::pair(prop_name, dtype->name())); (void)mem_allocations; @@ -185,55 +175,51 @@ GatherMemoryAllocation( void doMemoryAnalysis(const std::unique_ptr graph) { - memory_map mem_map = {}; - std::shared_ptr basic_raw_stats = {}; + FullReportMap mem_map = {}; + MemoryUsageMap basic_raw_stats = {}; auto node_schema = graph->full_node_schema(); auto edge_schema = graph->full_edge_schema(); int64_t total_num_node_props = node_schema->num_fields(); int64_t total_num_edge_props = edge_schema->num_fields(); - basic_raw_stats->insert(std::pair("Node-Schema-Size", total_num_node_props)); - basic_raw_stats->insert(std::pair("Edge-Schema-Size", total_num_edge_props)); - basic_raw_stats->insert( + basic_raw_stats.insert(std::pair("Node-Schema-Size", total_num_node_props)); + basic_raw_stats.insert(std::pair("Edge-Schema-Size", total_num_edge_props)); + basic_raw_stats.insert( std::pair("Number-Node-Atomic-Types", graph->GetNumNodeAtomicTypes())); - basic_raw_stats->insert( + basic_raw_stats.insert( std::pair("Number-Edge-Atomic-Types", graph->GetNumEdgeAtomicTypes())); - basic_raw_stats->insert( + basic_raw_stats.insert( std::pair("Number-Node-Entity-Types", graph->GetNumNodeEntityTypes())); - basic_raw_stats->insert( + basic_raw_stats.insert( std::pair("Number-Edge-Entity-Types", graph->GetNumNodeEntityTypes())); - basic_raw_stats->insert(std::pair("Number-Nodes", graph->num_nodes())); - basic_raw_stats->insert(std::pair("Number-Edges", graph->num_edges())); + basic_raw_stats.insert(std::pair("Number-Nodes", graph->num_nodes())); + basic_raw_stats.insert(std::pair("Number-Edges", graph->num_edges())); auto atomic_node_types = graph->ListAtomicNodeTypes(); auto atomic_edge_types = graph->ListAtomicEdgeTypes(); - std::shared_ptr all_node_prop_stats; - std::shared_ptr all_edge_prop_stats; - std::shared_ptr all_node_width_stats; - std::shared_ptr all_edge_width_stats; - std::shared_ptr all_node_alloc; - std::shared_ptr all_edge_alloc; - std::shared_ptr all_node_usage; - std::shared_ptr all_edge_usage; + TypeInformationMap all_node_prop_stats; + TypeInformationMap all_edge_prop_stats; + MemoryUsageMap all_node_width_stats; + MemoryUsageMap all_edge_width_stats; + MemoryUsageMap all_node_alloc; + MemoryUsageMap all_edge_alloc; + MemoryUsageMap all_node_usage; + MemoryUsageMap all_edge_usage; GatherMemoryAllocation( - node_schema, graph, all_node_alloc, all_node_usage, all_node_width_stats, - all_node_prop_stats, true); - - PrintMapping(all_node_prop_stats); - PrintMapping(all_node_usage); + node_schema, graph, &all_node_alloc, &all_node_usage, + &all_node_width_stats, &all_node_prop_stats, true); - mem_map.insert(std::pair("Node-Types", *all_node_prop_stats)); + mem_map.insert(std::pair("Node-Types", all_node_prop_stats)); GatherMemoryAllocation( - edge_schema, graph, all_edge_alloc, all_edge_usage, all_edge_width_stats, - all_edge_prop_stats, false); + edge_schema, graph, &all_edge_alloc, &all_edge_usage, + &all_edge_width_stats, &all_edge_prop_stats, false); - mem_map.insert(std::pair("Edge-Types", *all_edge_prop_stats)); + mem_map.insert(std::pair("Edge-Types", all_edge_prop_stats)); - mem_map.insert(std::pair("General-Stats", *basic_raw_stats)); - PrintMapping(basic_raw_stats); + mem_map.insert(std::pair("General-Stats", basic_raw_stats)); auto basic_raw_json_res = SaveToJson( katana::JsonDump(basic_raw_stats), outputfilename,