From: Paul_Woegerer@mentor.com (Woegerer, Paul)
Subject: [lttng-dev] Machine Interface
Date: Thu, 6 Feb 2014 18:07:22 +0100 [thread overview]
Message-ID: <52F3C14A.6020803@mentor.com> (raw)
In-Reply-To: <CAFXXi0=enX3ERpH1Q3R-P4ii2wU7TE2wX_NEcXYF0iEXKCW6yA@mail.gmail.com>
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.
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 17:07 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 [this message]
2014-02-06 18:40 ` Simon Marchi
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=52F3C14A.6020803@mentor.com \
--to=paul_woegerer@mentor.com \
/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