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>"
|
2014-02-23 23:37:02 +04:00
|
|
|
__copyright__ = "Copyright 2012-2014, 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 *')
|
|
|
|
if arg.lstrip().startswith(strtype):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2012-04-03 22:48:01 +04:00
|
|
|
|
|
|
|
def c(events):
|
|
|
|
out('#include "trace.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"',
|
2012-04-03 22:48:01 +04:00
|
|
|
'',
|
2013-03-05 17:47:55 +04:00
|
|
|
)
|
2012-07-18 13:45:59 +04:00
|
|
|
|
|
|
|
for num, event in enumerate(events):
|
2014-02-23 23:37:02 +04:00
|
|
|
out('void %(api)s(%(args)s)',
|
2012-07-18 13:45:59 +04:00
|
|
|
'{',
|
|
|
|
' TraceBufferRecord rec;',
|
2014-02-23 23:37:02 +04:00
|
|
|
api = event.api(),
|
2012-07-18 13:45:59 +04:00
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
|
|
out('',
|
2014-01-15 07:10:30 +04:00
|
|
|
' TraceEvent *eventp = trace_event_id(%(event_enum)s);',
|
2013-03-05 17:47:55 +04:00
|
|
|
' bool _state = trace_event_get_state_dynamic(eventp);',
|
|
|
|
' if (!_state) {',
|
2012-07-18 13:45:59 +04:00
|
|
|
' return;',
|
|
|
|
' }',
|
|
|
|
'',
|
|
|
|
' if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
|
|
|
|
' return; /* Trace Buffer Full, Event Dropped ! */',
|
|
|
|
' }',
|
2014-01-15 07:10:30 +04:00
|
|
|
event_enum = 'TRACE_' + event.name.upper(),
|
2012-07-18 13:45:59 +04:00
|
|
|
event_id = num,
|
|
|
|
size_str = sizestr,
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(event.args) > 0:
|
|
|
|
for type_, name in event.args:
|
|
|
|
# string
|
|
|
|
if is_string(type_):
|
|
|
|
out(' trace_record_write_str(&rec, %(name)s, arg%(name)s_len);',
|
|
|
|
name = name,
|
|
|
|
)
|
|
|
|
# pointer var (not string)
|
|
|
|
elif type_.endswith('*'):
|
2012-08-13 23:50:56 +04:00
|
|
|
out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
|
2012-07-18 13:45:59 +04:00
|
|
|
name = name,
|
|
|
|
)
|
|
|
|
# primitive data type
|
|
|
|
else:
|
|
|
|
out(' trace_record_write_u64(&rec, (uint64_t)%(name)s);',
|
|
|
|
name = name,
|
|
|
|
)
|
|
|
|
|
|
|
|
out(' trace_record_finish(&rec);',
|
|
|
|
'}',
|
|
|
|
'')
|
|
|
|
|
2012-04-03 22:48:01 +04:00
|
|
|
|
|
|
|
def h(events):
|
2012-07-18 13:45:59 +04:00
|
|
|
for event in events:
|
2014-02-23 23:37:02 +04:00
|
|
|
out('void %(api)s(%(args)s);',
|
|
|
|
api = event.api(),
|
2012-07-18 13:45:59 +04:00
|
|
|
args = event.args,
|
2012-04-03 22:48:01 +04:00
|
|
|
)
|