3 # Copyright (c) 2012 Yannick Brosseau <yannick.brosseau@gmail.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; only version 2
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 class Usage(Exception):
24 def __init__(self
, msg
):
29 #undef TRACEPOINT_PROVIDER
30 #define TRACEPOINT_PROVIDER {providerName}
32 #undef TRACEPOINT_INCLUDE_FILE
33 #define TRACEPOINT_INCLUDE_FILE ./{headerFilename}
37 #endif /*__cplusplus */
40 #if !defined({includeGuard}) || defined(TRACEPOINT_HEADER_MULTI_READ)
41 #define {includeGuard}
43 #include <lttng/tracepoint.h>
47 #endif /* {includeGuard} */
49 #include <lttng/tracepoint-event.h>
53 #endif /*__cplusplus */
56 def __init__(self
, filename
, template
):
57 self
.outputFilename
= filename
58 self
.template
= template
61 outputFile
= open(self
.outputFilename
,"w")
62 includeGuard
= "_"+self
.outputFilename
.upper().replace(".","_")
64 outputFile
.write(HeaderFile
.HEADER_TPL
.format(providerName
=self
.template
.domain
,
65 includeGuard
= includeGuard
,
66 headerFilename
= self
.outputFilename
))
67 outputFile
.write(self
.template
.text
)
68 outputFile
.write(HeaderFile
.FOOTER_TPL
.format(includeGuard
= includeGuard
))
73 #define TRACEPOINT_CREATE_PROBES
75 * The header containing our TRACEPOINT_EVENTs.
77 #define TRACEPOINT_DEFINE
78 #include "{headerFilename}"
80 def __init__(self
, filename
, template
):
81 self
.outputFilename
= filename
82 self
.template
= template
85 outputFile
= open(self
.outputFilename
,"w")
87 headerFilename
= self
.outputFilename
.replace(".c",".h")
89 outputFile
.write(CFile
.FILE_TPL
.format(
90 headerFilename
= headerFilename
))
94 def __init__(self
, filename
):
96 self
.inputFilename
= filename
100 def parseTemplate(self
):
101 f
= open(self
.inputFilename
,"r")
105 #Remove # comments (from input and output file
106 self
.text
= re
.sub("#.*$","",self
.text
,flags
=re
.MULTILINE
)
108 nolinecomment
= re
.sub("\/\/.*$","",self
.text
,flags
=re
.MULTILINE
)
109 #Remove all spaces and lines
110 cleantext
= re
.sub("\s*","",nolinecomment
)
111 #Remove multine C style comments
112 nocomment
= re
.sub("/\*.*?\*/","",cleantext
)
113 entries
= re
.split("TRACEPOINT_.*?",nocomment
)
115 for entry
in entries
:
117 decomp
= re
.findall("(\w*?)\((\w*?),(\w*?),", entry
)
119 domain
= decomp
[0][1]
122 if self
.domain
== "":
125 if self
.domain
!= domain
:
126 print "Warning: different domain provided (%s,%s)" % (self
.domain
, domain
)
129 lttng-gen-tp - Generate the LTTng-UST header and source based on a simple template
131 usage: lttng-gen-tp TEMPLATE_FILE [-o OUTPUT_FILE][-o OUTPUT_FILE]
133 If no OUTPUT_FILE is given, the .h and .c file will be generated.
134 (The basename of the template file with be used for the generated file.
135 for example sample.tp will generate sample.h and sample.c)
137 When using the -o option, the OUTPUT_FILE must end with either .h or .c
138 The -o option can be repeated multiple times.
140 The template file must contains TRACEPOINT_EVENT and TRACEPOINT_LOGLEVEL
141 as per defined in the lttng/tracepoint.h file.
142 See the lttng-ust(3) man page for more details on the format.
150 opts
, args
= getopt
.gnu_getopt(argv
[1:], "ho:a", ["help"])
151 except getopt
.error
, msg
:
155 print >>sys
.stderr
, err
.msg
156 print >>sys
.stderr
, "for help use --help"
161 if o
in ("-h", "--help"):
165 outputNames
.append(a
)
171 headerFilename
= None
174 if len(outputNames
) > 0:
176 print "Cannot process more than one input if you specify an output"
179 for outputName
in outputNames
:
180 if outputName
[-2:] == ".h":
182 headerFilename
= outputName
183 elif outputName
[-2:] == ".c":
185 cFilename
= outputName
186 elif outputName
[-2:] == ".o":
187 print "Not yet implemented, sorry"
189 print "output file type unsupported"
198 tpl
= TemplateFile(arg
)
201 curFilename
= headerFilename
203 curFilename
= re
.sub("\.tp$",".h",arg
)
204 doth
= HeaderFile(curFilename
, tpl
)
208 curFilename
= cFilename
210 curFilename
= re
.sub("\.tp$",".c",arg
)
211 dotc
= CFile(curFilename
, tpl
)
214 if __name__
== "__main__":
This page took 0.039055 seconds and 4 git commands to generate.