qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v5 11/20] trace: emit name <-> ID mapping in sim


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH v5 11/20] trace: emit name <-> ID mapping in simpletrace header
Date: Mon, 3 Oct 2016 14:57:14 +0100
User-agent: Mutt/1.7.0 (2016-08-17)

On Wed, Sep 28, 2016 at 02:08:14PM +0100, Daniel P. Berrange wrote:
>  def read_trace_records(edict, fobj):
>      """Deserialize trace records from a file, yielding record tuples 
> (event_num, timestamp, pid, arg1, ..., arg6)."""
> +    idtoname = {
> +        dropped_event_id: "dropped"
> +    }
>      while True:
> -        rec = read_record(edict, fobj)
> -        if rec is None:
> +        t = fobj.read(8)
> +        if len(t) == 0:
>              break
>  
> -        yield rec
> +        (rectype, ) = struct.unpack('=Q', t)
> +        if rectype == record_type_mapping:
> +            mapping = get_mapping(fobj)
> +            idtoname[mapping[0]] = mapping[1]

Unpacking the tuple makes the code easier to read:

event_id, name = get_mapping(fobj)
idtoname[event_id] = name

> diff --git a/scripts/tracetool/format/simpletrace_stap.py 
> b/scripts/tracetool/format/simpletrace_stap.py
> index 7e44bc1..ac3580f 100644
> --- a/scripts/tracetool/format/simpletrace_stap.py
> +++ b/scripts/tracetool/format/simpletrace_stap.py
> @@ -21,6 +21,25 @@ from tracetool.format.stap import stap_escape
>  
>  def generate(events, backend):
>      out('/* This file is autogenerated by tracetool, do not edit. */',
> +        '',
> +        'global event_name_to_id_map',
> +        'global event_next_id',
> +        'function simple_trace_map_event(name)',
> +        '',
> +        '{',
> +        '    if (!([name] in event_name_to_id_map)) {',
> +        '        event_name_to_id_map[name] = event_next_id',
> +        '        name_len = strlen(name)',
> +        '        printf("%%8b%%8b%%4b%%.*s", 0, ',
> +        '               event_next_id, name_len, name_len, name)',
> +        '        event_next_id = event_next_id + 1',
> +        '    }',
> +        '    return event_name_to_id_map[name]',
> +        '}',
> +        'probe begin',
> +        '{',
> +        '    printf("%%8b%%8b%%8b", 0xffffffffffffffff, 0xf2b177cb0aa429b4, 
> 4)',

The reason the SystemTap script doesn't emit a header is because it was
designed for trace flight-recorder mode.  There's probably no harm in
emitting the header.  Flight-recorder users will still have to use
--no-header though.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]