-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_tree.hpp
More file actions
63 lines (54 loc) · 2 KB
/
Copy pathfunc_tree.hpp
File metadata and controls
63 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <vector>
#include <unordered_map>
#include <set>
#include <omp.h>
#include <iostream>
extern "C" {
#include <igraph.h>
#include <igraph_attributes.h>
}
class FuncTree {
public:
FuncTree(std::string graph_path ,std::vector<std::unordered_map<std::string, std::string>> sym_tab_maps, int num_proc, std::vector<igraph_integer_t> nd_nodes): num_proc(num_proc), sym_tab_maps(sym_tab_maps), nd_nodes(nd_nodes){
igraph_t g;
igraph_set_attribute_table(&igraph_cattribute_table);
FILE* f = fopen(graph_path.c_str(), "r");
if (!f)
throw std::runtime_error("Cannot open input file: " + graph_path);
int err = igraph_read_graph_graphml(&g, f, 0);
fclose(f);
if (err != IGRAPH_SUCCESS)
throw std::runtime_error("Error reading GraphML: " + graph_path);
this->evg = g;
igraph_vector_init(&(this->pid), 0);
igraph_strvector_init(&(this->attr_callstack), 0);
VASV(&g, "callstack",&(this->attr_callstack));
VANV(&g, "process_id", &(this->pid));
this->callstack.resize(igraph_vcount(&g));
set_callstack();
create_func_graph();
annotate_func_graph();
}
~FuncTree(){
igraph_destroy(&evg);
igraph_destroy(&func_g);
igraph_vector_destroy(&pid);
igraph_strvector_destroy(&attr_callstack);
}
void set_callstack();
void create_func_graph();
void annotate_func_graph();
std::vector<std::pair<int,int>> get_edge_list() const;
std::vector<std::string> get_func_names() const;
std::vector<double> get_nd_scores() const { return nd_scores; }
private:
igraph_t evg, func_g;
igraph_vector_t pid;
igraph_strvector_t attr_callstack;
std::vector<std::vector<std::string>> callstack;
std::vector<igraph_integer_t> nd_nodes;
int num_proc;
std::vector<std::unordered_map<std::string, std::string>> sym_tab_maps;
std::vector<double> nd_scores;
std::unordered_map<std::string, int> func_name_to_id_map;
};