修訂 | 4e86df17326d2afaf74622c082d906ed3f96d1d7 (tree) |
---|---|
時間 | 2022-01-27 19:24:18 |
作者 | Vladimir Sementsov-Ogievskiy <vsementsov@virt...> |
Commiter | Markus Armbruster |
qapi/gen: Add FOO.trace-events output module
We are going to generate trace events for QMP commands. We should
generate both trace_*() function calls and trace-events files listing
events for trace generator.
So, add an output module FOO.trace-events for each FOO schema module.
Since we're going to add trace events only to command marshallers,
make the trace-events output optional, so we don't generate so many
useless empty files.
Currently nobody set add_trace_events to True, so new functionality is
disabled. It will be enabled for QAPISchemaGenCommandVisitor
in a further commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220126161130.3240892-2-vsementsov@virtuozzo.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
@@ -192,6 +192,11 @@ class QAPIGenH(QAPIGenC): | ||
192 | 192 | return guardend(self.fname) |
193 | 193 | |
194 | 194 | |
195 | +class QAPIGenTrace(QAPIGen): | |
196 | + def _top(self) -> str: | |
197 | + return super()._top() + '# AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n' | |
198 | + | |
199 | + | |
195 | 200 | @contextmanager |
196 | 201 | def ifcontext(ifcond: QAPISchemaIfCond, *args: QAPIGenCCode) -> Iterator[None]: |
197 | 202 | """ |
@@ -244,15 +249,18 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): | ||
244 | 249 | what: str, |
245 | 250 | user_blurb: str, |
246 | 251 | builtin_blurb: Optional[str], |
247 | - pydoc: str): | |
252 | + pydoc: str, | |
253 | + gen_tracing: bool = False): | |
248 | 254 | self._prefix = prefix |
249 | 255 | self._what = what |
250 | 256 | self._user_blurb = user_blurb |
251 | 257 | self._builtin_blurb = builtin_blurb |
252 | 258 | self._pydoc = pydoc |
253 | 259 | self._current_module: Optional[str] = None |
254 | - self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] = {} | |
260 | + self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH, | |
261 | + Optional[QAPIGenTrace]]] = {} | |
255 | 262 | self._main_module: Optional[str] = None |
263 | + self._gen_tracing = gen_tracing | |
256 | 264 | |
257 | 265 | @property |
258 | 266 | def _genc(self) -> QAPIGenC: |
@@ -264,6 +272,14 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): | ||
264 | 272 | assert self._current_module is not None |
265 | 273 | return self._module[self._current_module][1] |
266 | 274 | |
275 | + @property | |
276 | + def _gen_trace_events(self) -> QAPIGenTrace: | |
277 | + assert self._gen_tracing | |
278 | + assert self._current_module is not None | |
279 | + gent = self._module[self._current_module][2] | |
280 | + assert gent is not None | |
281 | + return gent | |
282 | + | |
267 | 283 | @staticmethod |
268 | 284 | def _module_dirname(name: str) -> str: |
269 | 285 | if QAPISchemaModule.is_user_module(name): |
@@ -293,7 +309,12 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): | ||
293 | 309 | basename = self._module_filename(self._what, name) |
294 | 310 | genc = QAPIGenC(basename + '.c', blurb, self._pydoc) |
295 | 311 | genh = QAPIGenH(basename + '.h', blurb, self._pydoc) |
296 | - self._module[name] = (genc, genh) | |
312 | + | |
313 | + gent: Optional[QAPIGenTrace] = None | |
314 | + if self._gen_tracing: | |
315 | + gent = QAPIGenTrace(basename + '.trace-events') | |
316 | + | |
317 | + self._module[name] = (genc, genh, gent) | |
297 | 318 | self._current_module = name |
298 | 319 | |
299 | 320 | @contextmanager |
@@ -304,11 +325,13 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): | ||
304 | 325 | self._current_module = old_module |
305 | 326 | |
306 | 327 | def write(self, output_dir: str, opt_builtins: bool = False) -> None: |
307 | - for name, (genc, genh) in self._module.items(): | |
328 | + for name, (genc, genh, gent) in self._module.items(): | |
308 | 329 | if QAPISchemaModule.is_builtin_module(name) and not opt_builtins: |
309 | 330 | continue |
310 | 331 | genc.write(output_dir) |
311 | 332 | genh.write(output_dir) |
333 | + if gent is not None: | |
334 | + gent.write(output_dir) | |
312 | 335 | |
313 | 336 | def _begin_builtin_module(self) -> None: |
314 | 337 | pass |