Try to read the text metadata if babeltrace failed
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 22 Feb 2016 17:54:20 +0000 (12:54 -0500)
committerAntoine Busque <abusque@efficios.com>
Wed, 24 Feb 2016 23:22:55 +0000 (18:22 -0500)
Reading a trace with babeltrace -o ctf-metadata fails if the metadata is
in text format instead of binary format. When we detect this error, try
to read the metadata with 'cat'.

Also, the traces generated with the CTFWriter API can only write strings
in the environment section for now, so we add optional quotes around the
version regex to allow extracting the version in these traces.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
lttnganalyses/cli/command.py

index 1445ea190e44d0683dd09e396ec17c1bc839761c..d0b19609cf1a0d0c6ad6063288522cd14b391144 100644 (file)
@@ -186,15 +186,25 @@ class Command:
             self._gen_error('Could not find kernel trace directory')
 
         try:
-            metadata = subprocess.getoutput(
+            ret, metadata = subprocess.getstatusoutput(
                 'babeltrace -o ctf-metadata "%s"' % kernel_path)
         except subprocess.CalledProcessError:
             self._gen_error('Cannot run babeltrace on the trace, cannot read'
                             ' tracer version')
 
-        major_match = re.search(r'tracer_major = (\d+)', metadata)
-        minor_match = re.search(r'tracer_minor = (\d+)', metadata)
-        patch_match = re.search(r'tracer_patchlevel = (\d+)', metadata)
+        # fallback to reading the text metadata if babeltrace failed to
+        # output the CTF metadata
+        if ret != 0:
+            try:
+                metadata = subprocess.getoutput(
+                    'cat "%s"' % os.path.join(kernel_path, 'metadata'))
+            except subprocess.CalledProcessError:
+                self._gen_error('Cannot read the metadata of the trace, cannot'
+                                'extract tracer version')
+
+        major_match = re.search(r'tracer_major = "*(\d+)"*', metadata)
+        minor_match = re.search(r'tracer_minor = "*(\d+)"*', metadata)
+        patch_match = re.search(r'tracer_patchlevel = "*(\d+)"*', metadata)
 
         if not major_match or not minor_match or not patch_match:
             self._gen_error('Malformed metadata, cannot read tracer version')
This page took 0.025022 seconds and 5 git commands to generate.