2012-04-03 22:48:01 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Simple built-in backend.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
|
2017-07-04 11:50:46 +03:00
|
|
|
__copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>"
|
2012-04-03 22:48:01 +04:00
|
|
|
__license__ = "GPL version 2 or (at your option) any later version"
|
|
|
|
|
|
|
|
__maintainer__ = "Stefan Hajnoczi"
|
|
|
|
__email__ = "stefanha@linux.vnet.ibm.com"
|
|
|
|
|
|
|
|
|
|
|
|
from tracetool import out
|
|
|
|
|
2013-03-05 17:47:26 +04:00
|
|
|
|
|
|
|
PUBLIC = True
|
|
|
|
|
|
|
|
|
2012-07-18 13:45:59 +04:00
|
|
|
def is_string(arg):
|
|
|
|
strtype = ('const char*', 'char*', 'const char *', 'char *')
|
2016-10-26 06:50:06 +03:00
|
|
|
arg_strip = arg.lstrip()
|
|
|
|
if arg_strip.startswith(strtype) and arg_strip.count('*') == 1:
|
2012-07-18 13:45:59 +04:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2012-04-03 22:48:01 +04:00
|
|
|
|
2014-02-23 23:37:40 +04:00
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def generate_h_begin(events, group):
|
2014-02-23 23:37:40 +04:00
|
|
|
for event in events:
|
|
|
|
out('void _simple_%(api)s(%(args)s);',
|
|
|
|
api=event.api(),
|
|
|
|
args=event.args)
|
|
|
|
out('')
|
|
|
|
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def generate_h(event, group):
|
2017-07-04 11:50:46 +03:00
|
|
|
out(' _simple_%(api)s(%(args)s);',
|
2014-02-23 23:37:40 +04:00
|
|
|
api=event.api(),
|
|
|
|
args=", ".join(event.args.names()))
|
|
|
|
|
|
|
|
|
2017-07-31 17:07:17 +03:00
|
|
|
def generate_h_backend_dstate(event, group):
|
|
|
|
out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
|
|
|
|
event_id="TRACE_" + event.name.upper())
|
|
|
|
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def generate_c_begin(events, group):
|
2016-02-08 21:53:31 +03:00
|
|
|
out('#include "qemu/osdep.h"',
|
2013-03-05 17:47:55 +04:00
|
|
|
'#include "trace/control.h"',
|
2012-07-18 13:45:59 +04:00
|
|
|
'#include "trace/simple.h"',
|
2014-02-23 23:37:40 +04:00
|
|
|
'')
|
|
|
|
|
|
|
|
|
2016-10-04 16:35:59 +03:00
|
|
|
def generate_c(event, group):
|
2014-02-23 23:37:40 +04:00
|
|
|
out('void _simple_%(api)s(%(args)s)',
|
|
|
|
'{',
|
|
|
|
' TraceBufferRecord rec;',
|
|
|
|
api=event.api(),
|
|
|
|
args=event.args)
|
|
|
|
sizes = []
|
|
|
|
for type_, name in event.args:
|
|
|
|
if is_string(type_):
|
|
|
|
out(' size_t arg%(name)s_len = %(name)s ? MIN(strlen(%(name)s), MAX_TRACE_STRLEN) : 0;',
|
|
|
|
name=name)
|
|
|
|
strsizeinfo = "4 + arg%s_len" % name
|
|
|
|
sizes.append(strsizeinfo)
|
|
|
|
else:
|
|
|
|
sizes.append("8")
|
|
|
|
sizestr = " + ".join(sizes)
|
|
|
|
if len(event.args) == 0:
|
|
|
|
sizestr = '0'
|
|
|
|
|
2016-07-11 13:53:46 +03:00
|
|
|
event_id = 'TRACE_' + event.name.upper()
|
|
|
|
if "vcpu" in event.properties:
|
|
|
|
# already checked on the generic format code
|
|
|
|
cond = "true"
|
|
|
|
else:
|
|
|
|
cond = "trace_event_get_state(%s)" % event_id
|
2014-02-23 23:37:40 +04:00
|
|
|
|
|
|
|
out('',
|
2016-07-11 13:53:46 +03:00
|
|
|
' if (!%(cond)s) {',
|
2014-02-23 23:37:40 +04:00
|
|
|
' return;',
|
|
|
|
' }',
|
2012-04-03 22:48:01 +04:00
|
|
|
'',
|
2016-10-04 16:35:49 +03:00
|
|
|
' if (trace_record_start(&rec, %(event_obj)s.id, %(size_str)s)) {',
|
2014-02-23 23:37:40 +04:00
|
|
|
' return; /* Trace Buffer Full, Event Dropped ! */',
|
|
|
|
' }',
|
2016-07-11 13:53:46 +03:00
|
|
|
cond=cond,
|
2016-10-04 16:35:49 +03:00
|
|
|
event_obj=event.api(event.QEMU_EVENT),
|
2014-02-23 23:37:40 +04:00
|
|
|
size_str=sizestr)
|
|
|
|
|
|
|
|
if len(event.args) > 0:
|
2012-07-18 13:45:59 +04:00
|
|
|
for type_, name in event.args:
|
2014-02-23 23:37:40 +04:00
|
|
|
# string
|
2012-07-18 13:45:59 +04:00
|
|
|
if is_string(type_):
|
2014-02-23 23:37:40 +04:00
|
|
|
out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
|
|
|
|
name=name)
|
|
|
|
# pointer var (not string)
|
|
|
|
elif type_.endswith('*'):
|
|
|
|
out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
|
|
|
|
name=name)
|
|
|
|
# primitive data type
|
2012-07-18 13:45:59 +04:00
|
|
|
else:
|
2014-02-23 23:37:40 +04:00
|
|
|
out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
|
|
|
|
name=name)
|
|
|
|
|
|
|
|
out(' trace_record_finish(&rec);',
|
|
|
|
'}',
|
|
|
|
'')
|