Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikitina2005 committed Jun 18, 2024
1 parent 640dfde commit ede147a
Show file tree
Hide file tree
Showing 70 changed files with 20,617 additions and 1,561 deletions.
7 changes: 7 additions & 0 deletions front/callgrind-front/callgrind-front/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Frontend for getting data from callgrind profiles.

Responsible persons:

Arman Yeghiazaryan, DCAM MIPT student: implementation

Nikolay Efanov, supervisor: review and advices on methodology
19 changes: 19 additions & 0 deletions front/callgrind-front/callgrind-front/callgrind-front.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# usual pipeline example for gprof:
# gprof ./main | gprof2dot -s | dot -Tpng -o output.png
# this script usage example:
# ./callgrind-front.sh tests/callgrind.out.2322 result.dot
# produces result.dot and result.dot.png in current working directory

# whole pipeline: ./callgrind-front.sh <profile> <profile_output_dot> <grammar_file> <parsed_dot> <res_file>
pwd
#produces dotfile
python3 ../../third-party/gprof2dot/gprof2dot.py ${1} --format=callgrind -c print -o ${2}
#parse dotfile and compose input for core algorithm (${3} is the path to your grammar file)
python3 graph_utils/dotparse.py ${2} ${4}
cat ${3} ${4} > ${5}
#run core
../../core/build/core < ${5}
#produces image file
dot ${2} -Tpng -o ${2}.png
79 changes: 79 additions & 0 deletions front/callgrind-front/callgrind-front/graph_utils/dotparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import pydot
import sys

#fmt:


def labels_encode(edges, labels=[]): # this is a hash-function for edge labeling, rewrite it as you need
d = dict()
for idx,l in enumerate(edges):
if l.__get_attribute__('label') in labels:
d[l.__get_attribute__('label')] = chr(ord('a')+idx)#l.get_source() + l.get_destination()

return d


def node_names_encode(labels=[]):
d = dict()
for idx,l in enumerate(labels):
d[l] = idx

return d


def verbose_print_edge(idx, e,lmap):
print("edge #", idx)
print("from: ", e.get_source())
print("to: ", e.get_destination())
print("old label: ", e.__get_attribute__('label'))
print("set label: ", lmap[e.__get_attribute__('label')] if e.__get_attribute__('label') in lmap.keys() else "")
return


def dotparse(inp, outp=None, labels=None, verbose=True, nodes_remap=True, edges_remap=True):
graph = pydot.graph_from_dot_file(inp)
node_list = graph[0].get_node_list()
if not labels:
labels = [el.__get_attribute__('label') for el in graph[0].get_edges()]
node_labels_map = node_names_encode([nl.get_name() for nl in node_list])
lmap = labels_encode(graph[0].get_edges(), labels)

if outp:
f = open(outp, "w")
nodes_amount = len(node_list)
edges_amount = len(graph[0].get_edges())
f.write(str(nodes_amount)+" "+str(edges_amount)+"\n")
for idx, e in enumerate(graph[0].get_edges()):
attr_orig = e.__get_attribute__('label') # NB: you also can populate labels with this info!
if verbose:
verbose_print_edge(idx, e, lmap)
# Triple of sets <$src$ \in $V$, $dst$ \in $E$, $current_label$ \in $L$> is all we need
src = e.get_source()
dst = e.get_destination()
current_label = lmap[attr_orig] if attr_orig in labels else "n" # "" means "not interested in this label"
if outp:
f.write(str(node_labels_map[src]) + " " + str(node_labels_map[dst]) + " " + current_label+"\n")
if outp:
f.close()
f=open(outp+".labels_remap","w")
f.write(str(edges_amount)+"\n")
for k,v in lmap.items():
f.write(k+" "+str(v)+"\n")
f.write(str(nodes_amount) + "\n")
for k,v in node_labels_map.items():
f.write(k+" "+str(v)+"\n")

return


if __name__ == "__main__":
if sys.argv[1] == 'test' or len(sys.argv) < 2:
dotparse("/Users/nefanov/PycharmProjects/pathfinder/front/callgrind-front/tests/callgrind.out.2322.dot",
labels=[],
verbose=False,
outp="labeled_edges_list.txt")
else:
dotparse(sys.argv[1],
verbose=False,
outp=sys.argv[2])

5 changes: 5 additions & 0 deletions front/callgrind-front/callgrind-front/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#test run example: 0 1 2 3 4 5
# whole pipeline: ./callgrind-front.sh <profile> <profile_output_dot> <grammar_file> <parsed_dot> <res_file>

./callgrind-front.sh tests/callgrind.out.1972 res.list tests/test.grammar res.inp core.inp
Loading

0 comments on commit ede147a

Please sign in to comment.