1717 * Documentation, or loss or inaccuracy of data of any kind.
1818 */
1919
20- #include < cstdlib>
2120#include < fstream>
2221#include < iostream>
2322#include < string>
2423#include < unordered_map>
25- #include < vector>
26- // Our special new must allocate memory as expected…
27- #include < cstdio>
28- // …but also inspect the stack and print some results.
29- #include < execinfo.h>
30- #include < unistd.h>
31-
32- // Import bad_alloc, expected in case of errors.
33- #include < stdlib.h>
34-
35- #include < type_traits>
36- #include < typeinfo>
37- #ifndef _MSC_VER
38- #include < cxxabi.h>
39- #endif
40- #include < memory>
4124
4225#include " katana/Galois.h"
43- #include " katana/LCGraph.h"
4426#include " katana/OfflineGraph.h"
4527#include " llvm/Support/CommandLine.h"
4628
47- template <class T >
48- std::string
49- type_name () {
50- typedef typename std::remove_reference<T>::type TR;
51- std::unique_ptr<char , void (*)(void *)> own (
52- #ifndef _MSC_VER
53- abi::__cxa_demangle (typeid (TR).name (), nullptr , nullptr , nullptr ),
54- #else
55- nullptr ,
56- #endif
57- std::free);
58- std::string r = own != nullptr ? own.get () : typeid (TR).name ();
59- if (std::is_const<TR>::value)
60- r += " const" ;
61- if (std::is_volatile<TR>::value)
62- r += " volatile" ;
63- if (std::is_lvalue_reference<T>::value)
64- r += " &" ;
65- else if (std::is_rvalue_reference<T>::value)
66- r += " &&" ;
67- return r;
68- }
69-
7029namespace cll = llvm::cl;
7130static cll::opt<std::string> inputfilename (
7231 cll::Positional, cll::desc(" graph-file" ), cll::Required);
7332
7433static cll::opt<std::string> outputfilename (
7534 cll::Positional, cll::desc(" out-file" ), cll::Required);
7635
77- // std::cout << "decltype(i) is " << type_name<decltype(i)>() << '\n';
7836void
7937PrintAtomicTypes (const std::vector<std::string>& atomic_types) {
8038 for (auto atype : atomic_types) {
@@ -84,16 +42,20 @@ PrintAtomicTypes(const std::vector<std::string>& atomic_types) {
8442
8543void
8644PrintMapping (const std::unordered_map<std::string, int64_t >& u) {
45+ std::cout << " \n " ;
8746 for (const auto & n : u) {
8847 std::cout << n.first << " : " << n.second << " \n " ;
8948 }
49+ std::cout << " \n " ;
9050}
9151
9252void
9353PrintStringMapping (const std::unordered_map<std::string, std::string>& u) {
54+ std::cout << " \n " ;
9455 for (const auto & n : u) {
9556 std::cout << n.first << " : " << n.second << " \n " ;
9657 }
58+ std::cout << " \n " ;
9759}
9860
9961void
@@ -117,7 +79,7 @@ InsertPropertyTypeMemoryData(
11779}
11880
11981void
120- doNonGroupingAnalysis (const std::unique_ptr<katana::PropertyGraph> graph) {
82+ doMemoryAnalysis (const std::unique_ptr<katana::PropertyGraph> graph) {
12183 using map_element = std::unordered_map<std::string, int64_t >;
12284 using map_string_element = std::unordered_map<std::string, std::string>;
12385 using memory_map = std::unordered_map<
@@ -129,10 +91,6 @@ doNonGroupingAnalysis(const std::unique_ptr<katana::PropertyGraph> graph) {
12991 int64_t total_num_node_props = node_schema->num_fields ();
13092 int64_t total_num_edge_props = edge_schema->num_fields ();
13193
132- // arrow::DataType TypeMap;
133-
134- // std::cout << static_cast<TypeMap>(0) << "\n";
135-
13694 basic_raw_stats.insert (std::pair (" Node-Schema-Size" , total_num_node_props));
13795 basic_raw_stats.insert (std::pair (" Edge-Schema-Size" , total_num_edge_props));
13896 basic_raw_stats.insert (
@@ -146,9 +104,6 @@ doNonGroupingAnalysis(const std::unique_ptr<katana::PropertyGraph> graph) {
146104 basic_raw_stats.insert (std::pair (" Number-Nodes" , graph->num_nodes ()));
147105 basic_raw_stats.insert (std::pair (" Number-Edges" , graph->num_edges ()));
148106
149- PrintMapping (basic_raw_stats);
150- mem_map.insert (std::pair (" General-Stats" , basic_raw_stats));
151-
152107 auto atomic_node_types = graph->ListAtomicNodeTypes ();
153108
154109 auto atomic_edge_types = graph->ListAtomicEdgeTypes ();
@@ -166,10 +121,6 @@ doNonGroupingAnalysis(const std::unique_ptr<katana::PropertyGraph> graph) {
166121 all_node_width_stats.insert (std::pair (" kUnknownName" , sizeof (uint8_t ) * 8 ));
167122 all_edge_width_stats.insert (std::pair (" kUnknownName" , sizeof (uint8_t ) * 8 ));
168123
169- std::cout << " \n " ;
170- std::cout << " Node Schema\n " ;
171- std::cout << " ---------------------------------------\n " ;
172-
173124 for (int32_t i = 0 ; i < node_schema->num_fields (); ++i) {
174125 std::string prop_name = node_schema->field (i)->name ();
175126 auto dtype = node_schema->field (i)->type ();
@@ -183,14 +134,9 @@ doNonGroupingAnalysis(const std::unique_ptr<katana::PropertyGraph> graph) {
183134 PrintMapping (all_node_width_stats);
184135 mem_map.insert (std::pair (" Node-Types" , all_node_prop_stats));
185136
186- std::cout << " \n " ;
187- std::cout << " Edge Schema\n " ;
188- std::cout << " ----------------------------------------\n " ;
189-
190137 for (int32_t i = 0 ; i < edge_schema->num_fields (); ++i) {
191138 std::string prop_name = edge_schema->field (i)->name ();
192139 auto dtype = edge_schema->field (i)->type ();
193-
194140 all_edge_width_stats.insert (
195141 std::pair (prop_name, arrow::bit_width (dtype->id ())));
196142 all_edge_prop_stats.insert (std::pair (prop_name, dtype->name ()));
@@ -201,41 +147,46 @@ doNonGroupingAnalysis(const std::unique_ptr<katana::PropertyGraph> graph) {
201147 mem_map.insert (std::pair (" Edge-Types" , all_edge_prop_stats));
202148
203149 auto node_iterator = g_topo.all_nodes ();
204- // auto edge_iterator = g_topo.all_edges();
150+ auto edge_iterator = g_topo.all_edges ();
205151
206152 int64_t width;
207- std::cout << " \n " ;
208153 int64_t node_size = 0 ;
154+ map_element node_dist;
155+ map_element edge_dist;
156+
209157 for (auto node : node_iterator) {
210158 std::string node_type = *graph->GetNodeAtomicTypeName (node);
211159 width = all_node_width_stats.find (node_type)->second ;
212- // std::cout << node_type << " : " << width << " ";
213- node_size += width;
160+ node_dist[node_type]++;
161+ node_size += width / 8 ;
162+ }
163+
164+ PrintMapping (node_dist);
165+ mem_map.insert (std::pair (" Node-Type-Distribution" , node_dist));
166+
167+ int64_t edge_size = 0 ;
168+ for (auto edge : edge_iterator) {
169+ std::string edge_type = *graph->GetEdgeAtomicTypeName (edge);
170+ width = all_edge_width_stats.find (edge_type)->second ;
171+ edge_dist[edge_type]++;
172+ edge_size += width / 8 ;
214173 }
215- std::cout << " Total Number of bytes taken up by Nodes: " << node_size << " \n " ;
216-
217- // int64_t edge_size = 0;
218- // for (auto edge : edge_iterator) {
219- // auto edge_type = graph->GetTypeOfEdge(edge);
220- // width = all_edge_width_stats.find(edge_type)->second;
221- // edge_size += width;
222- // std::cout << width << " ";
223- // }
224- // std::cout << "Total Number of bytes taken up by Edges: " << edge_size << "\n";
174+ PrintMapping (edge_dist);
175+ mem_map.insert (std::pair (" Edge-Type-Distribution" , edge_dist));
176+
177+ basic_raw_stats.insert (std::pair (" Node-Memory-Consumption" , node_size));
178+ basic_raw_stats.insert (std::pair (" Edge-Memory-Consumption" , edge_size));
179+
180+ mem_map.insert (std::pair (" General-Stats" , basic_raw_stats));
181+ PrintMapping (basic_raw_stats);
225182}
226183
227184int
228185main (int argc, char ** argv) {
229186 katana::SharedMemSys sys;
230187 llvm::cl::ParseCommandLineOptions (argc, argv);
231-
232- // ofstream memeory_file("example.txt");
233- // memeory_file.open();
234- // memeory_file << "File containing memory analysis of a graph.\n";
235- // memeory_file.close();
236-
237188 auto g = katana::PropertyGraph::Make (inputfilename, tsuba::RDGLoadOptions ());
238189 std::cout << " Graph Sizeof is: " << sizeof (g) << " \n " ;
239- doNonGroupingAnalysis (std::move (g.value ()));
190+ doMemoryAnalysis (std::move (g.value ()));
240191 return 1 ;
241192}
0 commit comments