From: simon.marchi@polymtl.ca (Simon Marchi)
Subject: [lttng-dev] Machine Interface
Date: Thu, 6 Feb 2014 13:40:10 -0500 [thread overview]
Message-ID: <CAFXXi0njQxw5t89ytKedE=mwKj_r2vY+cq=AyjzMe9Xoi=XVkg@mail.gmail.com> (raw)
In-Reply-To: <52F3C14A.6020803@mentor.com>
On 6 February 2014 12:07, Woegerer, Paul <Paul_Woegerer at mentor.com> wrote:
> Hi Simon,
>
> On 02/06/2014 02:32 PM, Simon Marchi wrote:
>> script) is easier than XML, but it's still not bulletproof. Consider
>> this eventual yaml structure I just made up for the output of the
>> session list.
>>
>> sessions:
>> - name: my_session
>> domain: kernel
>> events:
>> - name: sched_switch
>> filter: prev_pid == 1234
>> - name: sched_migrate_task
>> otherproperty: "something"
>> - name: another_session
>> domain: ust
>> events:
>> - name: event_hello
>> - name: event_bonjour
>> loglevel: 3
>>
>> If you want to get the list of sessions, you'll probably want to grep
>> the "name: " entries, but then event names would match as well. Of
>> course, names could be different, or you could grep for the
>> appropriate amount of spaces/tabs at the beginning of the line. But
>> then it also depends if the name dictionary entry is the first, then
>> it will have a "-" in front... It's possible, but it will also be very
>> easy to break scripts.
>
> The following simple script below would e.g. give you the list of
> sessions for you example above. To demonstrate the flexibility it
> also generates the event list for session my_session. This is just
> a quick prototype but it should make clear that YAML is considerably
> easier to parse from a shell script than any other option (and also
> reasonably robust). Also notice that no external helpers (like grep)
> are needed.
This is impressive scripting! Although I can see this growing a little
bit out of control for more complex yaml trees. I agree with you that
yaml is the easiest of them to parse in a pure shell script since the
formatting is more restricted. But if you're on a machine that can
take it, using a solution based on an XPath tool (or equivalent) will
make it so much more maintainable.
> list_of_sessions=''
> current_session=''
> my_session_events=''
>
> while IFS= read -r; do
> line=$REPLY
> case "${line}" in
> " - "*)
> ;&
> " "*)
> L2_key=${line:8}
> L2_key=${L2_key%:*}
> let vpos=2+8+${#L2_key}
> L2_value=${line:${vpos}}
> ;;
> " - "*)
> # New L1 list elem -> reset L2 state
> L2_key=''
> L2_value=''
> ;&
> " "*)
> L1_key=${line:4}
> L1_key=${L1_key%:*}
> let vpos=2+4+${#L1_key}
> L1_value=${line:${vpos}}
> ;;
> esac
> echo "($L1_key,$L1_value), ($L2_key,$L2_value)"
>
> # Collect the session names
> if [ "$L1_key" = "name" ]; then
> current_session="$L1_value"
> list_of_sessions="$list_of_sessions $current_session"
> fi
> # Which events are in session my_session ?
> if [ "$current_session" = "my_session" ] && [ "$L1_key" = "events" ] && [ "$L2_key" = "name" ]; then
> my_session_events="$my_session_events $L2_value"
> fi
> done
> echo
> echo List of sessions: $list_of_sessions
> echo my_session events: $my_session_events
> echo
>
>
> Thanks,
> Paul
>
> --
> Paul Woegerer, SW Development Engineer
> Sourcery Analyzer <http://go.mentor.com/sourceryanalyzer>
> Mentor Graphics, Embedded Software Division
next prev parent reply other threads:[~2014-02-06 18:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 2:42 Jonathan Rajotte
2014-02-06 7:41 ` Woegerer, Paul
2014-02-06 13:32 ` Simon Marchi
2014-02-06 17:07 ` Woegerer, Paul
2014-02-06 18:40 ` Simon Marchi [this message]
2014-02-06 16:11 ` Christian Babeux
2014-02-06 17:00 ` Jonathan Rajotte
2014-02-06 18:21 ` Christian Babeux
2014-02-06 13:51 Thibault, Daniel
2014-02-13 18:00 Olivier Cotte
2014-02-13 18:26 ` Simon Marchi
2014-02-13 19:16 ` Jonathan Rajotte
2014-02-13 20:05 Thibault, Daniel
2014-02-13 20:36 ` Jonathan Rajotte
2014-02-13 20:41 ` Thibault, Daniel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFXXi0njQxw5t89ytKedE=mwKj_r2vY+cq=AyjzMe9Xoi=XVkg@mail.gmail.com' \
--to=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox