def generate(events, backend, group): out('/* This file is autogenerated by tracetool, do not edit. */', '') for event_id, e in enumerate(events): if 'disable' in e.properties: continue out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?', '{', probeprefix=probeprefix(), name=e.name) # Calculate record size sizes = ['24'] # sizeof(TraceRecord) for type_, name in e.args: name = stap_escape(name) if is_string(type_): out(' try {', ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"', ' } catch {}', ' arg%(name)s_len = strlen(arg%(name)s_str)', name=name) sizes.append('4 + arg%s_len' % name) else: sizes.append('8') sizestr = ' + '.join(sizes) # Generate format string and value pairs for record header and arguments fields = [('8b', str(event_id)), ('8b', 'gettimeofday_ns()'), ('4b', sizestr), ('4b', 'pid()')] for type_, name in e.args: name = stap_escape(name) if is_string(type_): fields.extend([('4b', 'arg%s_len' % name), ('.*s', 'arg%s_len, arg%s_str' % (name, name))]) else: fields.append(('8b', name)) # Emit the entire record in a single SystemTap printf() fmt_str = '%'.join(fmt for fmt, _ in fields) arg_str = ', '.join(arg for _, arg in fields) out(' printf("%%8b%%%(fmt_str)s", 1, %(arg_str)s)', fmt_str=fmt_str, arg_str=arg_str) out('}') out()
def get_record(edict, idtoname, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" if rechdr is None: return None if rechdr[0] != dropped_event_id: event_id = rechdr[0] name = idtoname[event_id] rec = (name, rechdr[1], rechdr[3]) try: event = edict[name] except KeyError, e: import sys sys.stderr.write('%s event is logged but is not declared ' \ 'in the trace events file, try using ' \ 'trace-events-all instead.\n' % str(e)) sys.exit(1) for type, name in event.args: if is_string(type): l = fobj.read(4) (len, ) = struct.unpack('=L', l) s = fobj.read(len) rec = rec + (s, ) else: (value, ) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value, )
def get_record(edict, idtoname, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" if rechdr is None: return None if rechdr[0] != dropped_event_id: event_id = rechdr[0] name = idtoname[event_id] rec = (name, rechdr[1], rechdr[3]) try: event = edict[name] except KeyError, e: import sys sys.stderr.write('%s event is logged but is not declared ' \ 'in the trace events file, try using ' \ 'trace-events-all instead.\n' % str(e)) sys.exit(1) for type, name in event.args: if is_string(type): l = fobj.read(4) (len,) = struct.unpack('=L', l) s = fobj.read(len) rec = rec + (s,) else: (value,) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value,)
def generate(events, backend, group): out('/* This file is autogenerated by tracetool, do not edit. */', '') for event_id, e in enumerate(events): if 'disable' in e.properties: continue out('probe %(probeprefix)s.log.%(name)s = %(probeprefix)s.%(name)s ?', '{', probeprefix=probeprefix(), name=e.name) # Get references to userspace strings for type_, name in e.args: name = stap_escape(name) if is_string(type_): out(' try {', ' arg%(name)s_str = %(name)s ? ' + 'user_string_n(%(name)s, 512) : "<null>"', ' } catch {}', name=name) # Determine systemtap's view of variable names fields = ["pid()", "gettimeofday_ns()"] for type_, name in e.args: name = stap_escape(name) if is_string(type_): fields.append("arg" + name + "_str") else: fields.append(name) # Emit the entire record in a single SystemTap printf() arg_str = ', '.join(arg for arg in fields) fmt_str = "%d@%d " + e.name + " " + c_fmt_to_stap(e.fmt) + "\\n" out(' printf("%(fmt_str)s", %(arg_str)s)', fmt_str=fmt_str, arg_str=arg_str) out('}') out()
def catchall(self, event, rec): i = 1 timestamp = rec[1] if self.last_timestamp is None: self.last_timestamp = timestamp delta_ns = timestamp - self.last_timestamp self.last_timestamp = timestamp fields = [event.name, '%0.3f' % (delta_ns / 1000.0)] for type, name in event.args: if is_string(type): fields.append('%s=%s' % (name, rec[i + 1])) else: fields.append('%s=0x%x' % (name, rec[i + 1])) i += 1 print ' '.join(fields)
def get_record(edict, rechdr, fobj): """Deserialize a trace record from a file into a tuple (event_num, timestamp, arg1, ..., arg6).""" if rechdr is None: return None rec = (rechdr[0], rechdr[1]) if rechdr[0] != dropped_event_id: event_id = rechdr[0] event = edict[event_id] for type, name in event.args: if is_string(type): l = fobj.read(4) (len,) = struct.unpack('=L', l) s = fobj.read(len) rec = rec + (s,) else: (value,) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value,) else: (value,) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value,) return rec
def get_record(edict, idtoname, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" if rechdr is None: return None if rechdr[0] != dropped_event_id: event_id = rechdr[0] name = idtoname[event_id] rec = (name, rechdr[1], rechdr[3]) event = edict[name] for type, name in event.args: if is_string(type): l = fobj.read(4) (len, ) = struct.unpack('=L', l) s = fobj.read(len) rec = rec + (s, ) else: (value, ) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value, ) else: rec = ("dropped", rechdr[1], rechdr[3]) (value, ) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value, ) return rec
def get_record(edict, idtoname, rechdr, fobj): """Deserialize a trace record from a file into a tuple (name, timestamp, pid, arg1, ..., arg6).""" if rechdr is None: return None if rechdr[0] != dropped_event_id: event_id = rechdr[0] name = idtoname[event_id] rec = (name, rechdr[1], rechdr[3]) event = edict[name] for type, name in event.args: if is_string(type): l = fobj.read(4) (len,) = struct.unpack('=L', l) s = fobj.read(len) rec = rec + (s,) else: (value,) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value,) else: rec = ("dropped", rechdr[1], rechdr[3]) (value,) = struct.unpack('=Q', fobj.read(8)) rec = rec + (value,) return rec
def generate(events, backend, group): id_map = global_var_name("event_name_to_id_map") next_id = global_var_name("event_next_id") map_func = global_var_name("simple_trace_map_event") out('/* This file is autogenerated by tracetool, do not edit. */', '', 'global %(id_map)s', 'global %(next_id)s', 'function %(map_func)s(name)', '', '{', ' if (!([name] in %(id_map)s)) {', ' %(id_map)s[name] = %(next_id)s', ' name_len = strlen(name)', ' printf("%%8b%%8b%%4b%%.*s", 0, ', ' %(next_id)s, name_len, name_len, name)', ' %(next_id)s = %(next_id)s + 1', ' }', ' return %(id_map)s[name]', '}', 'probe begin', '{', ' printf("%%8b%%8b%%8b", 0xffffffffffffffff, 0xf2b177cb0aa429b4, 4)', '}', '', id_map=id_map, next_id=next_id, map_func=map_func) for event_id, e in enumerate(events): if 'disable' in e.properties: continue out('probe %(probeprefix)s.simpletrace.%(name)s = %(probeprefix)s.%(name)s ?', '{', ' id = %(map_func)s("%(name)s")', probeprefix=probeprefix(), map_func=map_func, name=e.name) # Calculate record size sizes = ['24'] # sizeof(TraceRecord) for type_, name in e.args: name = stap_escape(name) if is_string(type_): out(' try {', ' arg%(name)s_str = %(name)s ? user_string_n(%(name)s, 512) : "<null>"', ' } catch {}', ' arg%(name)s_len = strlen(arg%(name)s_str)', name=name) sizes.append('4 + arg%s_len' % name) else: sizes.append('8') sizestr = ' + '.join(sizes) # Generate format string and value pairs for record header and arguments fields = [('8b', 'id'), ('8b', 'gettimeofday_ns()'), ('4b', sizestr), ('4b', 'pid()')] for type_, name in e.args: name = stap_escape(name) if is_string(type_): fields.extend([('4b', 'arg%s_len' % name), ('.*s', 'arg%s_len, arg%s_str' % (name, name))]) else: fields.append(('8b', name)) # Emit the entire record in a single SystemTap printf() fmt_str = '%'.join(fmt for fmt, _ in fields) arg_str = ', '.join(arg for _, arg in fields) out(' printf("%%8b%%%(fmt_str)s", 1, %(arg_str)s)', fmt_str=fmt_str, arg_str=arg_str) out('}') out()