-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-profile-tables.py
140 lines (110 loc) · 4.46 KB
/
make-profile-tables.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#######################################################################
# This file is part of FLINT.
#
# FLINT is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# FLINT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FLINT; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
#
# Script for generating profiling information tables for C modules being
# profiled by profiler-main.c.
#
# It takes one command-line parameter: the name of the module, e.g. "xyz".
# It reads through xyz-profile.c, pulls out function names having certain
# initial substrings, and builds a file xyz-profile-tables.c which should
# be linked against xyz-profile.c and profiler-main.c.
#
# See the makefile for typical usage. See also profiler-main.c.
#
# (C) 2007 William Hart and David Harvey
#
###############################################################################
import sys
import re
if len(sys.argv) != 2:
raise ValueError, "no file specified"
module = sys.argv[1]
############ process input file
cfilename = module + "-profile.c"
cfile = open(cfilename)
profDriver_re = re.compile("void profDriver_(.*)\(.*")
profDriverString_re = re.compile("char\* profDriverString_(.*)\(.*")
profDriverDefaultParams_re = re.compile("char\* profDriverDefaultParams_(.*)\(.*")
prof_re = [profDriver_re, profDriverString_re, profDriverDefaultParams_re]
# dictionary from profile name to a tuple of bools, indicating which
# functions are defined for each target
prof_data = {}
for line in cfile:
for i in range(len(prof_re)):
m = prof_re[i].match(line)
if m is not None:
name = m.group(1)
if name not in prof_data:
prof_data[name] = [False] * len(prof_re)
else:
if prof_data[name][i]:
raise ValueError, "duplicate target \"%s\"" % name
prof_data[name][i] = True
############ generate output file
tfilename = module + "-profile-tables.c"
tfile = open(tfilename, "w")
tfile.write(
"/* ===================================================================\n"
"\n"
" " + tfilename + "\n"
"\n"
" This file was AUTOMATICALLY GENERATED by make-profile-tables.py.\n"
" DO NOT EDIT IT -- your changes will go the way of all LOST SOCKS.\n"
"\n"
"=================================================================== */\n"
"\n"
)
tfile.write("#include <stdlib.h>\n")
tfile.write("#include \"profiler-main.h\"\n")
tfile.write("\n")
tfile.write("char* prof_module_name = \"" + module + "\";\n\n")
tfile.write("int prof_target_count = %s;\n\n" % len(prof_data))
for (name, flags) in prof_data.iteritems():
if flags[0]:
tfile.write("extern void profDriver_%s(char* params);\n" % name)
if flags[1]:
tfile.write("extern char* profDriverString_%s(char* params);\n" % name)
if flags[2]:
tfile.write("extern char* profDriverDefaultParams_%s();\n" % name)
tfile.write("\n")
tfile.write("char* prof_target_name[] = {\n")
for (name, flags) in prof_data.iteritems():
tfile.write(" \"%s\",\n" % name)
tfile.write("};\n\n")
tfile.write("prof_Driver_t prof_Driver_list[] = {\n")
for (name, flags) in prof_data.iteritems():
if flags[0]:
tfile.write(" profDriver_%s,\n" % name)
else:
tfile.write(" NULL,\n")
tfile.write("};\n\n")
tfile.write("prof_DriverString_t prof_DriverString_list[] = {\n")
for (name, flags) in prof_data.iteritems():
if flags[1]:
tfile.write(" profDriverString_%s,\n" % name)
else:
tfile.write(" NULL,\n")
tfile.write("};\n\n")
tfile.write("prof_DriverDefaultParams_t prof_DriverDefaultParams_list[] = {\n")
for (name, flags) in prof_data.iteritems():
if flags[2]:
tfile.write(" profDriverDefaultParams_%s,\n" % name)
else:
tfile.write(" NULL,\n")
tfile.write("};\n\n")
########### end of file