 736ec1677f
			
		
	
	
		736ec1677f
		
	
	
	
	
		
			
			The trace-events "disable" keyword turns an event into a nop at compile-time. This is important for high-frequency events that can impact performance. The "disable" keyword is currently broken in the simple trace backend. This patch fixes the problem as follows: Trace events are identified by their TraceEventID number. When events are disabled there are two options for assigning TraceEventID numbers: 1. Skip disabled events and don't assign them a number. 2. Assign numbers for all events regardless of the disabled keyword. The simple trace backend and its binary file format uses approach #1. The tracetool infrastructure has been using approach #2 for a while. The result is that the numbers used in simple trace files do not correspond with TraceEventIDs. In trace/simple.c we assumed that they are identical and therefore emitted bogus numbers. This patch fixes the bug by using TraceEventID for trace_event_id() while sticking to approach #1 for simple trace file numbers. This preserves simple trace file format compatibility. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
		
			
				
	
	
		
			102 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python
 | |
| # -*- coding: utf-8 -*-
 | |
| 
 | |
| """
 | |
| Simple built-in backend.
 | |
| """
 | |
| 
 | |
| __author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
 | |
| __copyright__  = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
 | |
| __license__    = "GPL version 2 or (at your option) any later version"
 | |
| 
 | |
| __maintainer__ = "Stefan Hajnoczi"
 | |
| __email__      = "stefanha@linux.vnet.ibm.com"
 | |
| 
 | |
| 
 | |
| from tracetool import out
 | |
| 
 | |
| 
 | |
| PUBLIC = True
 | |
| 
 | |
| 
 | |
| def is_string(arg):
 | |
|     strtype = ('const char*', 'char*', 'const char *', 'char *')
 | |
|     if arg.lstrip().startswith(strtype):
 | |
|         return True
 | |
|     else:
 | |
|         return False
 | |
| 
 | |
| def c(events):
 | |
|     out('#include "trace.h"',
 | |
|         '#include "trace/control.h"',
 | |
|         '#include "trace/simple.h"',
 | |
|         '',
 | |
|         )
 | |
| 
 | |
|     for num, event in enumerate(events):
 | |
|         out('void trace_%(name)s(%(args)s)',
 | |
|             '{',
 | |
|             '    TraceBufferRecord rec;',
 | |
|             name = event.name,
 | |
|             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('',
 | |
|             '    TraceEvent *eventp = trace_event_id(%(event_enum)s);',
 | |
|             '    bool _state = trace_event_get_state_dynamic(eventp);',
 | |
|             '    if (!_state) {',
 | |
|             '        return;',
 | |
|             '    }',
 | |
|             '',
 | |
|             '    if (trace_record_start(&rec, %(event_id)s, %(size_str)s)) {',
 | |
|             '        return; /* Trace Buffer Full, Event Dropped ! */',
 | |
|             '    }',
 | |
|             event_enum = 'TRACE_' + event.name.upper(),
 | |
|             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('*'):
 | |
|                     out('    trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);',
 | |
|                         name = name,
 | |
|                        )
 | |
|                 # primitive data type
 | |
|                 else:
 | |
|                     out('    trace_record_write_u64(&rec, (uint64_t)%(name)s);',
 | |
|                        name = name,
 | |
|                        )
 | |
| 
 | |
|         out('    trace_record_finish(&rec);',
 | |
|             '}',
 | |
|             '')
 | |
| 
 | |
| 
 | |
| def h(events):
 | |
|     for event in events:
 | |
|         out('void trace_%(name)s(%(args)s);',
 | |
|             name = event.name,
 | |
|             args = event.args,
 | |
|             )
 |