Allow user to specify fields forming the period marker key
authorAntoine Busque <abusque@efficios.com>
Wed, 28 Oct 2015 06:38:05 +0000 (02:38 -0400)
committerAntoine Busque <abusque@efficios.com>
Wed, 28 Oct 2015 06:38:05 +0000 (02:38 -0400)
Signed-off-by: Antoine Busque <abusque@efficios.com>
lttnganalyses/cli/command.py
lttnganalyses/core/analysis.py

index a54e584128b3a9ac2a3ca6035258e6664dc6275d..85bb3a5aa30227380babe4a18bba49d865ad0856 100644 (file)
@@ -117,6 +117,7 @@ class Command:
         self._analysis_conf.refresh_period = refresh_period_ns
         self._analysis_conf.period_begin_ev_name = args.period_begin
         self._analysis_conf.period_end_ev_name = args.period_end
+        self._analysis_conf.period_key_fields = args.period_key.split(',')
 
         # convert min/max args from µs to ns, if needed
         if hasattr(args, 'min') and args.min is not None:
@@ -168,6 +169,9 @@ class Command:
         ap.add_argument('--period-end', type=str,
                         help='Analysis period end marker event name '
                         '(requires --period-begin)')
+        ap.add_argument('--period-key', type=str, default='cpu_id',
+                        help='Optional, list of event field names used to match '
+                        'period markers (default: cpu_id)')
         ap.add_argument('-V', '--version', action='version',
                         version='LTTng Analyses v' + __version__)
 
index ea519c8174c2100a71f241f6263fb8a0c3897606..a24bac1984b254c8842a26ada0e4243b4065771c 100644 (file)
@@ -30,6 +30,7 @@ class AnalysisConfig:
         self.refresh_period = None
         self.period_begin_ev_name = None
         self.period_end_ev_name = None
+        self.period_key_fields = None
         self.begin_ts = None
         self.end_ts = None
         self.min_duration = None
@@ -75,7 +76,8 @@ class Analysis:
         raise NotImplementedError()
 
     def end(self):
-        self._end_period()
+        if self._period_start_ts:
+            self._end_period()
 
     def register_notification_cbs(self, cbs):
         for name in cbs:
@@ -130,7 +132,7 @@ class Analysis:
 
         period_key = self._get_period_event_key(ev)
         if not period_key:
-            # There was an error caused by missing context, ignore
+            # There was an error caused by a missing field, ignore
             # this period event
             return
 
@@ -145,7 +147,7 @@ class Analysis:
                     self._end_period()
                     self._period_key = period_key
                     self._period_start_ts = ev.timestamp
-        else:
+        elif ev.name == self._conf.period_begin_ev_name:
             self._period_key = period_key
             self._period_start_ts = ev.timestamp
 
@@ -160,14 +162,16 @@ class Analysis:
         pass
 
     def _get_period_event_key(self, ev):
-        # TODO: currently the key is hardcoded to the vtid of the
-        # thread which generated the event, but eventually there
-        # should be the option for a user to specify what fields
-        # (context or payload) make up the key.
-        try:
-            key = ev.vtid
-        except AttributeError:
-            # TODO warn user of missing context?
-            key = None
-
-        return key
+        if not self._conf.period_key_fields:
+            return None
+
+        key_values = []
+
+        for field in self._conf.period_key_fields:
+            try:
+                key_values.append(ev[field])
+            except KeyError:
+                # Error: missing field
+                return None
+
+        return tuple(key_values)
This page took 0.026105 seconds and 5 git commands to generate.