Merge lp:~mhr3/libunity/easy-tracing into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Michal Hruby
Approved revision: 311
Merged at revision: 306
Proposed branch: lp:~mhr3/libunity/easy-tracing
Merge into: lp:libunity
Diff against target: 619 lines (+295/-36)
14 files modified
debian/libunity9.symbols (+1/-0)
src/unity-aggregator-scope-private.vala (+20/-9)
src/unity-deprecated-scope-impl.vala (+3/-2)
src/unity-models.vala (+3/-0)
src/unity-scope-dbus-impl.vala (+2/-2)
src/unity-scope-tracker.vala (+3/-2)
src/unity-search.vala (+2/-4)
src/unity-synchronizer.vala (+6/-3)
src/unity-trace.c (+3/-5)
src/unity-trace.h (+3/-1)
test/vala/Makefile.am (+8/-1)
test/vala/test-results-synchronizer.vala (+1/-1)
tools/capture-trace.py (+225/-0)
tools/unity-tool.vala (+15/-6)
To merge this branch: bzr merge lp:~mhr3/libunity/easy-tracing
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Paweł Stołowski (community) Approve
Review via email: mp+189497@code.launchpad.net

Commit message

Make tracing easy.

Description of the change

Make tracing easy using new capture_trace.py script in tools/.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Nice stuff, +1!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

Looks like unrelated race in Dee that caused a failure here.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/libunity9.symbols'
--- debian/libunity9.symbols 2013-10-24 15:19:00 +0000
+++ debian/libunity9.symbols 2013-10-25 14:15:10 +0000
@@ -689,6 +689,7 @@
689 unity_string_array_wrapper_take_strings@Base 4.0.6689 unity_string_array_wrapper_take_strings@Base 4.0.6
690 unity_trace_log_object_real@Base 5.0.0690 unity_trace_log_object_real@Base 5.0.0
691 unity_trace_log_object_va@Base 5.0.0691 unity_trace_log_object_va@Base 5.0.0
692 unity_trace_tracepoint_va@Base 0replaceme
692 unity_track_metadata_construct@Base 4.0.0693 unity_track_metadata_construct@Base 4.0.0
693 unity_track_metadata_construct_full@Base 5.92.0694 unity_track_metadata_construct_full@Base 5.92.0
694 unity_track_metadata_get_album@Base 4.0.0695 unity_track_metadata_get_album@Base 4.0.0
695696
=== modified file 'src/unity-aggregator-scope-private.vala'
--- src/unity-aggregator-scope-private.vala 2013-10-24 11:27:10 +0000
+++ src/unity-aggregator-scope-private.vala 2013-10-25 14:15:10 +0000
@@ -1194,13 +1194,13 @@
1194 if (measure_requests) search_start_time = get_monotonic_time ();1194 if (measure_requests) search_start_time = get_monotonic_time ();
1195 int64 search_end_time = search_start_time;1195 int64 search_end_time = search_start_time;
11961196
1197 Unity.Trace.tracepoint ("%s run start: %s", Log.METHOD, owner.id);
1198
1199 var glib_cancellable = search_cancellable.get_gcancellable ();1197 var glib_cancellable = search_cancellable.get_gcancellable ();
1200 ulong canc_sig_id = 0;1198 ulong canc_sig_id = 0;
1201 uint canc_src_id = 0;1199 uint canc_src_id = 0;
1202 bool was_cancelled = false;1200 bool was_cancelled = false;
12031201
1202 Unity.Trace.tracepoint ("search:start::scope=%s;query=%s", owner.id, search_string);
1203
1204 // danger ahead, we're running the search in (possibly) different thread1204 // danger ahead, we're running the search in (possibly) different thread
1205 // and at the same time waiting for the cancellable while holding1205 // and at the same time waiting for the cancellable while holding
1206 // channel lock (ChannelState set to SEARCH_ACTIVE), other searches won't1206 // channel lock (ChannelState set to SEARCH_ACTIVE), other searches won't
@@ -1246,6 +1246,8 @@
1246 yield;1246 yield;
1247 }1247 }
12481248
1249 Unity.Trace.tracepoint ("search:end::scope=%s;query=%s", owner.id, search_string);
1250
1249 if (search_cancellable.is_cancelled ())1251 if (search_cancellable.is_cancelled ())
1250 {1252 {
1251 throw new ScopeError.SEARCH_CANCELLED ("Search '%s' was cancelled", search_string);1253 throw new ScopeError.SEARCH_CANCELLED ("Search '%s' was cancelled", search_string);
@@ -1262,8 +1264,6 @@
1262 response.insert (key, variant);1264 response.insert (key, variant);
1263 }1265 }
12641266
1265 Unity.Trace.tracepoint ("%s run end: %s", Log.METHOD, owner.id);
1266
1267 result_set.flush ();1267 result_set.flush ();
1268 response[SEARCH_SEQNUM_HINT] = new Variant.uint64 (channel.get_last_seqnum ());1268 response[SEARCH_SEQNUM_HINT] = new Variant.uint64 (channel.get_last_seqnum ());
1269 if (measure_requests)1269 if (measure_requests)
@@ -1351,10 +1351,21 @@
1351 if (category_merger is CategoryMergerByScope)1351 if (category_merger is CategoryMergerByScope)
1352 (category_merger as CategoryMergerByScope).add_scope_mapping (owner, master_scope_id);1352 (category_merger as CategoryMergerByScope).add_scope_mapping (owner, master_scope_id);
13531353
1354 var channel = get_channel_by_id (channel_id);1354 Unity.Trace.tracepoint ("push:start::scope=%s;target=%s;query=%s",
1355 yield _scopes.push_wrapper (channel, search_string, ChannelType.GLOBAL,1355 master_scope_id, scope_id, search_string);
1356 master_scope_id, scope_id,1356
1357 results_model, category_ids, cancellable);1357 try
1358 {
1359 var channel = get_channel_by_id (channel_id);
1360 yield _scopes.push_wrapper (channel, search_string, ChannelType.GLOBAL,
1361 master_scope_id, scope_id,
1362 results_model, category_ids, cancellable);
1363 }
1364 finally
1365 {
1366 Unity.Trace.tracepoint ("push:end::scope=%s;target=%s;query=%s",
1367 master_scope_id, scope_id, search_string);
1368 }
1358 }1369 }
13591370
1360 public void push_filter_settings (string channel_id, FilterSet filters)1371 public void push_filter_settings (string channel_id, FilterSet filters)
@@ -1456,7 +1467,7 @@
1456 }1467 }
14571468
1458 _channels[channel.id] = channel;1469 _channels[channel.id] = channel;
1459 _scopes.register_channel (channel.id, channel.backend_model, merge_strategy);1470 _scopes.register_channel (owner.id, channel.id, channel.backend_model, merge_strategy);
14601471
1461 out_hints = new HashTable<string, Variant> (str_hash, str_equal);1472 out_hints = new HashTable<string, Variant> (str_hash, str_equal);
1462 out_hints[CHANNEL_SWARM_NAME_HINT] = new Variant.string (model_name);1473 out_hints[CHANNEL_SWARM_NAME_HINT] = new Variant.string (model_name);
14631474
=== modified file 'src/unity-deprecated-scope-impl.vala'
--- src/unity-deprecated-scope-impl.vala 2013-09-24 08:57:39 +0000
+++ src/unity-deprecated-scope-impl.vala 2013-10-25 14:15:10 +0000
@@ -491,7 +491,7 @@
491 if (measure_requests) search_start_time = get_monotonic_time ();491 if (measure_requests) search_start_time = get_monotonic_time ();
492 int64 search_end_time = search_start_time;492 int64 search_end_time = search_start_time;
493493
494 Unity.Trace.tracepoint ("%s run start: %s", Log.METHOD, owner.id);494 Unity.Trace.tracepoint ("search:start::scope=%s", owner.id);
495495
496 new_search.run_async (() =>496 new_search.run_async (() =>
497 {497 {
@@ -506,7 +506,8 @@
506 result[SEARCH_SEQNUM_HINT] = new Variant.uint64 (channel.get_last_seqnum ());506 result[SEARCH_SEQNUM_HINT] = new Variant.uint64 (channel.get_last_seqnum ());
507 }507 }
508508
509 Unity.Trace.tracepoint ("%s run end: %s", Log.METHOD, owner.id);509 Unity.Trace.tracepoint ("search:end::scope=%s", owner.id);
510
510 if (measure_requests)511 if (measure_requests)
511 {512 {
512 int64 delta_us = search_end_time - search_start_time;513 int64 delta_us = search_end_time - search_start_time;
513514
=== modified file 'src/unity-models.vala'
--- src/unity-models.vala 2013-07-17 15:18:49 +0000
+++ src/unity-models.vala 2013-10-25 14:15:10 +0000
@@ -119,6 +119,7 @@
119 var sm = flush_model as Dee.SharedModel;119 var sm = flush_model as Dee.SharedModel;
120 if (sm != null)120 if (sm != null)
121 {121 {
122 Unity.Trace.tracepoint ("flush::%s", sm.get_swarm_name ());
122 sm.flush_revision_queue ();123 sm.flush_revision_queue ();
123 }124 }
124 }125 }
@@ -195,6 +196,7 @@
195 return;196 return;
196 }197 }
197198
199 Unity.Trace.tracepoint ("diff:start::%s", get_swarm_name ());
198 var script = Utils.Diff.run ((int) this_rows, (int) target_rows,200 var script = Utils.Diff.run ((int) this_rows, (int) target_rows,
199 (index_a, index_b) =>201 (index_a, index_b) =>
200 {202 {
@@ -249,6 +251,7 @@
249 }251 }
250 }252 }
251 }253 }
254 Unity.Trace.tracepoint ("diff:end::%s", get_swarm_name ());
252255
253 assert (get_n_rows () == target_model.get_n_rows ());256 assert (get_n_rows () == target_model.get_n_rows ());
254 }257 }
255258
=== modified file 'src/unity-scope-dbus-impl.vala'
--- src/unity-scope-dbus-impl.vala 2013-09-24 08:57:39 +0000
+++ src/unity-scope-dbus-impl.vala 2013-10-25 14:15:10 +0000
@@ -566,7 +566,7 @@
566 if (measure_requests) search_start_time = get_monotonic_time ();566 if (measure_requests) search_start_time = get_monotonic_time ();
567 int64 search_end_time = search_start_time;567 int64 search_end_time = search_start_time;
568568
569 Unity.Trace.tracepoint ("%s run start: %s", Log.METHOD, _dbus_name);569 Unity.Trace.tracepoint ("search:start::scope=%s;query=%s", _dbus_name, normalized_query);
570570
571 if (force_sync_requests)571 if (force_sync_requests)
572 {572 {
@@ -590,7 +590,7 @@
590 yield;590 yield;
591 }591 }
592592
593 Unity.Trace.tracepoint ("%s run end: %s", Log.METHOD, _dbus_name);593 Unity.Trace.tracepoint ("search:end::scope=%s;query=%s", _dbus_name, normalized_query);
594594
595 // FIXME: handle no-reply-hint etc!595 // FIXME: handle no-reply-hint etc!
596 if (!cancellable.is_cancelled ())596 if (!cancellable.is_cancelled ())
597597
=== modified file 'src/unity-scope-tracker.vala'
--- src/unity-scope-tracker.vala 2013-09-24 08:57:39 +0000
+++ src/unity-scope-tracker.vala 2013-10-25 14:15:10 +0000
@@ -224,12 +224,13 @@
224 return "%p::%d".printf (proxy, (int) channel_type);224 return "%p::%d".printf (proxy, (int) channel_type);
225 }225 }
226226
227 public void register_channel (string master_channel_id,227 public void register_channel (string owner_scope_id,
228 string master_channel_id,
228 Dee.SerializableModel model,229 Dee.SerializableModel model,
229 MergeStrategy merge_strategy)230 MergeStrategy merge_strategy)
230 {231 {
231 // create new synchronizer for this channel232 // create new synchronizer for this channel
232 var synchronizer = new ResultsSynchronizer (model);233 var synchronizer = new ResultsSynchronizer (model, owner_scope_id);
233 synchronizer.merge_strategy = merge_strategy;234 synchronizer.merge_strategy = merge_strategy;
234 synchronizers[master_channel_id] = synchronizer;235 synchronizers[master_channel_id] = synchronizer;
235 }236 }
236237
=== modified file 'src/unity-search.vala'
--- src/unity-search.vala 2013-07-22 14:02:05 +0000
+++ src/unity-search.vala 2013-10-25 14:15:10 +0000
@@ -176,10 +176,10 @@
176 }176 }
177 var agg_scope = owner as AggregatorScope;177 var agg_scope = owner as AggregatorScope;
178 var canc = search_context.cancellable.get_gcancellable ();178 var canc = search_context.cancellable.get_gcancellable ();
179 Unity.Trace.tracepoint ("%s start: %s, query=%s", Log.METHOD, scope_id, search_string);179 Unity.Trace.tracepoint ("subsearch:start::scope=%s;target=%s;query=%s", agg_scope.id, scope_id, search_string);
180 var res = yield agg_scope.search_scope (this, scope_id, search_string,180 var res = yield agg_scope.search_scope (this, scope_id, search_string,
181 search_type, hints, canc);181 search_type, hints, canc);
182 Unity.Trace.tracepoint ("%s end: %s, query=%s", Log.METHOD, scope_id, search_string);182 Unity.Trace.tracepoint ("subsearch:end::scope=%s;target=%s;query=%s", agg_scope.id, scope_id, search_string);
183 return res;183 return res;
184 }184 }
185185
@@ -190,11 +190,9 @@
190 if (search_context.cancellable.is_cancelled ()) return;190 if (search_context.cancellable.is_cancelled ()) return;
191 var agg_scope = owner as AggregatorScope;191 var agg_scope = owner as AggregatorScope;
192 var canc = search_context.cancellable.get_gcancellable ();192 var canc = search_context.cancellable.get_gcancellable ();
193 Unity.Trace.tracepoint ("%s start: %s", Log.METHOD, scope_id);
194 yield agg_scope.push_results (channel_id, search_string,193 yield agg_scope.push_results (channel_id, search_string,
195 scope_id, results_model,194 scope_id, results_model,
196 category_ids, canc);195 category_ids, canc);
197 Unity.Trace.tracepoint ("%s end: %s", Log.METHOD, scope_id);
198 }196 }
199197
200 public void push_filter_settings (FilterSet filters)198 public void push_filter_settings (FilterSet filters)
201199
=== modified file 'src/unity-synchronizer.vala'
--- src/unity-synchronizer.vala 2013-05-10 12:14:18 +0000
+++ src/unity-synchronizer.vala 2013-10-25 14:15:10 +0000
@@ -38,6 +38,7 @@
38 }38 }
3939
40 public unowned Dee.Model receiver { get; construct; }40 public unowned Dee.Model receiver { get; construct; }
41 public string owner_scope_id { get; construct; }
41 public MergeStrategy merge_strategy { get; set; }42 public MergeStrategy merge_strategy { get; set; }
4243
43 private Gee.Set<Dee.Model> _providers;44 private Gee.Set<Dee.Model> _providers;
@@ -50,9 +51,9 @@
50 private Quark scope_id_quark = Quark.from_string ("scope-id");51 private Quark scope_id_quark = Quark.from_string ("scope-id");
51 private uint _clear_seq_num = 1;52 private uint _clear_seq_num = 1;
5253
53 internal ResultsSynchronizer (Dee.Model receiver)54 internal ResultsSynchronizer (Dee.Model receiver, string scope_id)
54 {55 {
55 Object (receiver:receiver);56 Object (receiver:receiver, owner_scope_id: scope_id);
56 }57 }
5758
58 construct59 construct
@@ -184,9 +185,11 @@
184 private void transaction_finished (Dee.SharedModel model,185 private void transaction_finished (Dee.SharedModel model,
185 uint64 begin_sn, uint64 end_sn)186 uint64 begin_sn, uint64 end_sn)
186 {187 {
188 unowned string scope_id = model.get_qdata<string> (scope_id_quark);
189 Unity.Trace.tracepoint ("changeset::scope=%s;target=%s", owner_scope_id, scope_id);
187 if (model in _providers)190 if (model in _providers)
188 {191 {
189 transaction_complete (model, model.get_qdata<string> (scope_id_quark));192 transaction_complete (model, scope_id);
190 }193 }
191 }194 }
192195
193196
=== modified file 'src/unity-trace.c'
--- src/unity-trace.c 2013-04-04 06:49:22 +0000
+++ src/unity-trace.c 2013-10-25 14:15:10 +0000
@@ -58,14 +58,12 @@
58 va_end (args);58 va_end (args);
59}59}
6060
61#ifdef ENABLE_LTTNG
62
63void61void
64unity_trace_tracepoint_real (const gchar *format, va_list args)62unity_trace_tracepoint_va (const gchar *format, va_list args)
65{63{
64#ifdef ENABLE_LTTNG
66 gchar *tmp = g_strdup_vprintf (format, args);65 gchar *tmp = g_strdup_vprintf (format, args);
67 tracepoint (libunity, message, tmp);66 tracepoint (libunity, message, tmp);
68 g_free (tmp);67 g_free (tmp);
68#endif
69}69}
70
71#endif
7270
=== modified file 'src/unity-trace.h'
--- src/unity-trace.h 2013-04-04 11:47:25 +0000
+++ src/unity-trace.h 2013-10-25 14:15:10 +0000
@@ -90,11 +90,13 @@
90#endif /* ENABLE_UNITY_TRACE_LOG */90#endif /* ENABLE_UNITY_TRACE_LOG */
9191
92#ifdef ENABLE_LTTNG92#ifdef ENABLE_LTTNG
93void unity_trace_tracepoint_va (const gchar *format, va_list args);
94
93static void unity_trace_tracepoint (const gchar *format, ...)95static void unity_trace_tracepoint (const gchar *format, ...)
94{96{
95 va_list args;97 va_list args;
96 va_start (args, format);98 va_start (args, format);
97 unity_trace_tracepoint_real (format, args);99 unity_trace_tracepoint_va (format, args);
98 va_end (args);100 va_end (args);
99}101}
100#else102#else
101103
=== modified file 'test/vala/Makefile.am'
--- test/vala/Makefile.am 2013-07-04 23:07:03 +0000
+++ test/vala/Makefile.am 2013-10-25 14:15:10 +0000
@@ -52,7 +52,12 @@
52 $(top_builddir)/src/libunity.la \52 $(top_builddir)/src/libunity.la \
53 $(top_builddir)/protocol/libunity-protocol-private.la \53 $(top_builddir)/protocol/libunity-protocol-private.la \
54 $(top_builddir)/extras/libunity-extras.la \54 $(top_builddir)/extras/libunity-extras.la \
55 $(LIBUNITY_LIBS)55 $(LIBUNITY_LIBS) \
56 $(NULL)
57
58if ENABLE_LTTNG
59test_libs += -lurcu-bp
60endif
5661
57TEST_PROGS += test-vala test-scope test-blacklist-crash test-extras62TEST_PROGS += test-vala test-scope test-blacklist-crash test-extras
5863
@@ -86,6 +91,8 @@
86nodist_test_blacklist_crash_SOURCES = $(test_blacklist_crash_VALASOURCES:.vala=.c)91nodist_test_blacklist_crash_SOURCES = $(test_blacklist_crash_VALASOURCES:.vala=.c)
8792
88test_extras_LDADD = $(test_libs)93test_extras_LDADD = $(test_libs)
94test_extras_LDFLAGS = -static
95
89test_extras_VALASOURCES = \96test_extras_VALASOURCES = \
90 test-preview-player-iface.vala \97 test-preview-player-iface.vala \
91 test-utils.vala \98 test-utils.vala \
9299
=== modified file 'test/vala/test-results-synchronizer.vala'
--- test/vala/test-results-synchronizer.vala 2013-02-26 14:04:40 +0000
+++ test/vala/test-results-synchronizer.vala 2013-10-25 14:15:10 +0000
@@ -40,7 +40,7 @@
40 var provider2 = new Dee.SequenceModel ();40 var provider2 = new Dee.SequenceModel ();
41 provider2.set_schema_full (RESULTS_SCHEMA);41 provider2.set_schema_full (RESULTS_SCHEMA);
42 provider2.set_data<string> ("scope-id", "scope2");42 provider2.set_data<string> ("scope-id", "scope2");
43 var res_sync = new Internal.ResultsSynchronizer (receiver);43 var res_sync = new Internal.ResultsSynchronizer (receiver, "master.scope");
44 res_sync.add_provider (provider1, "scope1");44 res_sync.add_provider (provider1, "scope1");
45 res_sync.add_provider (provider2, "scope2");45 res_sync.add_provider (provider2, "scope2");
4646
4747
=== added file 'tools/capture-trace.py'
--- tools/capture-trace.py 1970-01-01 00:00:00 +0000
+++ tools/capture-trace.py 2013-10-25 14:15:10 +0000
@@ -0,0 +1,225 @@
1#!/usr/bin/env python
2
3import os, sys
4import subprocess
5import re
6
7"""
8# This script has two modes of operation:
9#
10# 1) Capture a trace and generate a html visualization.
11# To use this mode just run `./capture_trace.py`. This will setup a lttng
12# session, enable all userspace trace events and spawns a subshell where
13# you can for example run libunity-tool to perform a search on a scope.
14# When the subshell exits, tracing is stopped and visualization is generated.
15#
16# 2) Only generate a html visualization of a previously captured trace.
17# Use `./capture_trace.py /path/to/lttng/trace_dir`.
18#
19# Note that use use the first mode you need to have lttng installed
20# and libunity compiled with --enable-lttng option.
21# Required packages (besides requirements for libunity's --enable-lttng):
22# sudo apt-get install lttng-tools babeltrace
23"""
24
25"""
26# --- Manually capturing a trace
27# lttng create session_name
28# lttng enable-event -u -a
29# lttng start
30# --- start home scope with lttng-enabled branch of libunity, perform a search
31# lttng stop
32# lttng destroy
33# --- view the trace in cli
34# babeltrace ~/lttng_traces/<session_name dir>
35"""
36def capture_lttng_trace():
37 session = subprocess.check_output(["lttng", "create", "libunity-trace"], stdin=subprocess.PIPE)
38 trace_started = False
39 try:
40 subprocess.check_output(["lttng", "enable-event", "-u", "-a"], stdin=subprocess.PIPE)
41 subprocess.check_output(["lttng", "start"], stdin=subprocess.PIPE)
42 trace_started = True
43 sys.stderr.write("Trace running... Close this sub-shell with Ctrl+D to finish\n")
44 subprocess.check_call(["bash"]) # let this inherit our stdin
45 except subprocess.CalledProcessError as cpe:
46 if trace_started:
47 # bash will return non-zero exit code if you for example Ctrl+C
48 # a program within it, let's just ignore those errors
49 msg = "Warning: subshell returned error: " + str(cpe.returncode)
50 sys.stderr.write(msg + "\n")
51 else: raise
52 finally:
53 if trace_started:
54 subprocess.check_output(["lttng", "stop"], stdin=subprocess.PIPE)
55 subprocess.check_output(["lttng", "destroy", "libunity-trace"], stdin=subprocess.PIPE)
56
57 match = re.findall(r'Traces will be written in (.+)', session)
58 if len(match) > 0: return match[0]
59 return None
60
61# trace event example
62"""
63[20:00:30.697493680] (+0.000014138) miso-ThinkPad:unity-scope-hom:26439 libunity:message: { cpu_id = 0 }, { message = "flush::com.canonical.Unity.Master.Scope.home.T296521243842038" }
64"""
65
66def parse_trace_line(line):
67 pattern = re.compile(r'^\[(?P<timestamp>[0-9:\.]+)\].+?{ message = "(?P<msg>[^"]+)"')
68 match = pattern.match(line)
69 timestamp = match.group("timestamp")
70 msg = match.group("msg")
71 msg_parts = msg.split("::", 2)
72 if len(msg_parts) > 1:
73 msg_type = msg_parts[0]
74 msg = {}
75 for kv in msg_parts[1].split(";"):
76 items = kv.split("=", 2)
77 if len(items) > 1:
78 msg[items[0]] = items[1]
79 else:
80 msg['content'] = items[0]
81 else:
82 msg_type = "other"
83 msg = {'content': msg}
84
85 return (timestamp, msg_type, msg)
86
87def find_end_event(events, searched_event, event_type):
88 for i in range(len(events)):
89 event = events[i]
90 if event[1] == event_type and event[2] == searched_event[2]:
91 return i
92 return -1
93
94def pair_events(events):
95 paired = []
96 i = 0
97 while i < len(events):
98 event = events[i]
99 event_type = event[1]
100 if event_type.endswith(":start"):
101 group = event[1].split(":", 2)[0]
102 j = find_end_event(events[i+1:], event, group + ":end")
103 if j >= 0:
104 end_event = events.pop(i+j+1)
105 paired.append((event, end_event))
106 i = i+1
107 continue
108 paired.append((event, None))
109 i = i+1
110
111 return paired
112
113COLOR_FOR_EVENT = {
114 'search': "'#394a6b'",
115 'subsearch': "'#109618'",
116 'changeset': "'#990099'",
117 'diff': "'#e57357'",
118 'flush': "'#ff9900'",
119 'push': "'#0099c6'"
120}
121
122def produce_html(trace_name, pairs):
123 base = """<html><head><title>%s</title></head><body>
124<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization',
125 'version':'1','packages':['timeline']}]}"></script>
126<script type="text/javascript">
127
128google.setOnLoadCallback(drawChart);
129function drawChart() {
130 var dataTable = new google.visualization.DataTable();
131
132 dataTable.addColumn({ type: 'string', id: 'group' });
133 dataTable.addColumn({ type: 'string', id: 'id' });
134 dataTable.addColumn({ type: 'string', id: 'data' });
135 dataTable.addColumn({ type: 'datetime', id: 'Start' });
136 dataTable.addColumn({ type: 'datetime', id: 'End' });
137
138 dataTable.addRows([
139 %s
140 ]);
141
142 var view = new google.visualization.DataView(dataTable);
143 view.setColumns([0,1,3,4]);
144
145 var container = document.getElementById('example2.1');
146 var chart = new google.visualization.Timeline(container);
147
148 chart.draw(view);
149}
150</script>
151
152<div id="example2.1" style="height: 100%%;"></div>
153</body></html>"""
154 rows = []
155 colors = []
156 for pair in pairs:
157 (start_event, end_event) = pair
158 (timestamp, event_type, metadata) = start_event
159 has_end_ts = end_event is not None
160
161 group = event_type if not event_type.endswith(":start") else event_type.split(":", 2)[0]
162 color = COLOR_FOR_EVENT[group] if group in COLOR_FOR_EVENT else "'#c60000'"
163 has_scope_id = 'scope' in metadata
164 scope_id = metadata['scope'] if has_scope_id else metadata['content']
165 if has_scope_id: del metadata['scope']
166 else:
167 if group in ['changeset', 'flush', 'diff']:
168 match = re.match(r'com.canonical.Unity\.Master\.Scope\.(\w+)\.T', scope_id)
169 if match: scope_id = "%s.scope" % match.group(1)
170 data = str(metadata).replace("'", "\\'")
171
172 # we're loosing our lovely nanosecond precision :(
173 map_to_int = lambda x: int(x[0:3])
174 start_date = map(map_to_int, re.findall(r'\d+', timestamp))
175 end_date = start_date
176 if has_end_ts:
177 end_date = map(map_to_int, re.findall(r'\d+', end_event[0]))
178
179 event_name = "%s - %s" % (group, metadata['target']) if 'target' in metadata else group
180 data_tuple = (scope_id, group, data, ",".join(map(str,start_date)), ",".join(map(str, end_date)))
181 data_format = "[ '%s', '%s', '%s', new Date(0,0,0,%s), new Date(0,0,0,%s) ]"
182 data_row = data_format % data_tuple
183 rows.append(data_row)
184 colors.append(color)
185 return base % ("Analysis of %s" % trace_name, ",\n".join(rows))
186
187def get_events_from_babeltrace(trace_dir):
188 events = []
189 all_events = subprocess.check_output(["babeltrace", trace_dir])
190 lines = filter(None, all_events.split("\n"))
191 for line in lines:
192 event = parse_trace_line(line)
193 events.append(event)
194 return events
195
196def main(args):
197 output_name = None
198 if len(args) > 1:
199 trace_dir = args[1]
200 else:
201 trace_dir = capture_lttng_trace()
202
203 if trace_dir:
204 basename = os.path.basename(trace_dir)
205 if not basename:
206 basename = os.path.basename(os.path.dirname(trace_dir))
207 output_name = "%s.html" % basename
208
209 events = get_events_from_babeltrace(trace_dir)
210 if len(events) == 0:
211 raise RuntimeError("There are 0 events in the trace")
212 pairs = pair_events(events)
213 html = produce_html(trace_dir, pairs)
214
215 if output_name:
216 sys.stderr.write("Writing output to '%s'\n" % output_name)
217 f = open(output_name, 'w')
218 f.write(html)
219 f.close()
220 else:
221 print html
222
223if __name__ == "__main__":
224 main (sys.argv)
225
0226
=== modified file 'tools/unity-tool.vala'
--- tools/unity-tool.vala 2013-10-04 16:08:32 +0000
+++ tools/unity-tool.vala 2013-10-25 14:15:10 +0000
@@ -35,6 +35,7 @@
35 public static bool print_search_reply;35 public static bool print_search_reply;
36 public static bool dump_results;36 public static bool dump_results;
37 public static bool dump_filters;37 public static bool dump_filters;
38 public static bool diff_changes;
3839
39 public static bool test_server_mode;40 public static bool test_server_mode;
40 public static string[] test_cases;41 public static string[] test_cases;
@@ -104,6 +105,10 @@
104 "Use private channel for results transfer", null105 "Use private channel for results transfer", null
105 },106 },
106 {107 {
108 "diff-changes", 'd', 0, OptionArg.NONE, out Options.diff_changes,
109 "Use diff channel", null
110 },
111 {
107 "test-server-mode", 0, 0, OptionArg.NONE, out Options.test_server_mode,112 "test-server-mode", 0, 0, OptionArg.NONE, out Options.test_server_mode,
108 "Run a collection of test scripts", null113 "Run a collection of test scripts", null
109 },114 },
@@ -238,12 +243,10 @@
238 // Get proxy243 // Get proxy
239 string channel_id;244 string channel_id;
240 Dee.SerializableModel results_model;245 Dee.SerializableModel results_model;
241 var flags = Options.private_channel ?
242 ChannelFlags.PRIVATE : ChannelFlags.NONE;
243 var proxy = get_scope_proxy (Options.scope_dbus_name,246 var proxy = get_scope_proxy (Options.scope_dbus_name,
244 Options.scope_dbus_path,247 Options.scope_dbus_path,
245 (ChannelType) Options.search_type,248 (ChannelType) Options.search_type,
246 flags,249 get_global_channel_flags (),
247 out channel_id, out results_model);250 out channel_id, out results_model);
248251
249 // Performing search252 // Performing search
@@ -508,18 +511,24 @@
508 return Test.run ();511 return Test.run ();
509 }512 }
510513
514 private static ChannelFlags get_global_channel_flags ()
515 {
516 var flags = ChannelFlags.NONE;
517 if (Options.private_channel) flags |= ChannelFlags.PRIVATE;
518 if (Options.diff_changes) flags |= ChannelFlags.DIFF_CHANGES;
519 return flags;
520 }
521
511 private static void call_scope_search (string search_string,522 private static void call_scope_search (string search_string,
512 int search_type)523 int search_type)
513 {524 {
514 string channel_id;525 string channel_id;
515 Dee.SerializableModel results_model;526 Dee.SerializableModel results_model;
516527
517 var flags = Options.private_channel ?
518 ChannelFlags.PRIVATE : ChannelFlags.NONE;
519 var proxy = get_scope_proxy (Options.scope_dbus_name,528 var proxy = get_scope_proxy (Options.scope_dbus_name,
520 Options.scope_dbus_path,529 Options.scope_dbus_path,
521 (ChannelType) search_type,530 (ChannelType) search_type,
522 flags,531 get_global_channel_flags (),
523 out channel_id, out results_model);532 out channel_id, out results_model);
524533
525 var ml = new MainLoop ();534 var ml = new MainLoop ();

Subscribers

People subscribed via source and target branches