1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5Syslog built-in backend.
6"""
7
8__author__     = "Paul Durrant <paul.durrant@citrix.com>"
9__copyright__  = "Copyright 2016, Citrix Systems Inc."
10__license__    = "GPL version 2 or (at your option) any later version"
11
12__maintainer__ = "Stefan Hajnoczi"
13__email__      = "stefanha@redhat.com"
14
15
16from tracetool import out
17
18
19PUBLIC = True
20
21
22def generate_h_begin(events):
23    out('#include <syslog.h>',
24        '#include "trace/control.h"',
25        '')
26
27
28def generate_h(event):
29    argnames = ", ".join(event.args.names())
30    if len(event.args) > 0:
31        argnames = ", " + argnames
32
33    if "vcpu" in event.properties:
34        # already checked on the generic format code
35        cond = "true"
36    else:
37        cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
38
39    out('        if (%(cond)s) {',
40        '            syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
41        '        }',
42        cond=cond,
43        name=event.name,
44        fmt=event.fmt.rstrip("\n"),
45        argnames=argnames)
46