jameschennerd commited on
Commit
b1b2b5e
·
verified ·
1 Parent(s): fe15c62

Delete extract_from_markdowns.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. extract_from_markdowns.py +0 -105
extract_from_markdowns.py DELETED
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env python3
2
- import os
3
- import json
4
-
5
- def get_project(callsite):
6
- projects = [
7
- 'redis',
8
- 'zfs',
9
- 'wrk',
10
- 'gcc',
11
- 'ffmpeg',
12
- 'curl',
13
- 'openssh'
14
- ]
15
-
16
- for p in projects:
17
- if p in callsite:
18
- return p
19
-
20
- print('Unknown callsite:', callsite)
21
- return 'unknown'
22
-
23
- history = {}
24
-
25
- def parse(lines, kind):
26
- results = {}
27
- next_is_callsite = False
28
- next_is_code = False
29
- codes = []
30
- for line in lines:
31
- if next_is_callsite:
32
- if line.startswith('*'):
33
- callsite = line.strip()[1:-1]
34
- project = get_project(callsite)
35
- if callsite in history:
36
- print(callsite)
37
-
38
- history[callsite] = True
39
-
40
- if project not in results:
41
- results[project] = {}
42
-
43
- results[project].update({
44
- callsite: {
45
- "callsite" : "",
46
- "type": kind,
47
- "chain_summary": [],
48
- "callees": {
49
- }
50
- }
51
- })
52
- next_is_callsite = False
53
-
54
- if line.startswith('```'):
55
- if len(codes) > 0:
56
- results[project][callsite]['chain_summary'].append({
57
- 'source_code': codes,
58
- 'parent': "",
59
- })
60
- codes = []
61
- next_is_code = False
62
-
63
- if next_is_code:
64
- codes.append(line[:-1])
65
-
66
- if line.startswith('## Callsite'):
67
- next_is_callsite = True
68
-
69
- if line.startswith('fnptr: '):
70
- fnptr = line.strip().split(' ')[-1][1:-1]
71
- results[project][callsite]['callsite'] = fnptr
72
-
73
- if line.startswith('targets: '):
74
- targets = line.strip().split(': ')[-1].split(', ')
75
- results[project][callsite]['callees']['targets'] = {t:"" for t in targets}
76
-
77
- if line.startswith('```c'):
78
- next_is_code = True
79
-
80
- return results
81
-
82
-
83
- def main():
84
- results = {}
85
- for dirpath, dirs, files in os.walk(os.curdir):
86
- fpaths = [os.path.join(dirpath, f) for f in files if f.endswith('.md')]
87
- for fpath in fpaths:
88
- with open(fpath, 'r') as fp:
89
- data = parse([l for l in fp.readlines() if l.strip()], os.path.basename(fpath)[:-3])
90
- print(fpath, len(data))
91
-
92
- if len(results) == 0:
93
- results.update(data)
94
-
95
- for k in data:
96
- if k in results:
97
- results[k].update(data[k])
98
- else:
99
- results[k] = data[k]
100
-
101
- with open(os.path.join(os.curdir, 'cgbench.json'), 'w') as fp:
102
- fp.write(json.dumps(results, indent=4))
103
-
104
- if __name__ == '__main__':
105
- main()