[lttng-dev] [PATCH] Python agent: Support Agent protocol v2.0

Jérémie Galarneau jeremie.galarneau at efficios.com
Fri Oct 23 17:12:50 EDT 2015


Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
---
 liblttng-ust-python-agent/lttngust/agent.py |  2 +-
 liblttng-ust-python-agent/lttngust/cmd.py   | 26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/liblttng-ust-python-agent/lttngust/agent.py b/liblttng-ust-python-agent/lttngust/agent.py
index 84cfd83..ebfa2de 100644
--- a/liblttng-ust-python-agent/lttngust/agent.py
+++ b/liblttng-ust-python-agent/lttngust/agent.py
@@ -40,7 +40,7 @@ except ImportError:
 
 
 _PROTO_DOMAIN = 5
-_PROTO_MAJOR = 1
+_PROTO_MAJOR = 2
 _PROTO_MINOR = 0
 
 
diff --git a/liblttng-ust-python-agent/lttngust/cmd.py b/liblttng-ust-python-agent/lttngust/cmd.py
index fe180fa..382de68 100644
--- a/liblttng-ust-python-agent/lttngust/cmd.py
+++ b/liblttng-ust-python-agent/lttngust/cmd.py
@@ -2,6 +2,7 @@
 #
 # Copyright (C) 2015 - Philippe Proulx <pproulx at efficios.com>
 # Copyright (C) 2014 - David Goulet <dgoulet at efficios.com>
+# Copyright (C) 2015 - Jérémie Galarneau <jeremie.galarneau at efficios.com>
 #
 # This library is free software; you can redistribute it and/or modify it under
 # the terms of the GNU Lesser General Public License as published by the Free
@@ -29,6 +30,10 @@ _server_cmd_header_struct = struct.Struct('>QII')
 _SERVER_CMD_HEADER_SIZE = _server_cmd_header_struct.size
 
 
+# agent protocol symbol size
+_LTTNG_SYMBOL_NAME_LEN = 256
+
+
 class _ServerCmdHeader(object):
     def __init__(self, data_size, cmd_id, cmd_version):
         self.data_size = data_size
@@ -64,21 +69,36 @@ class _ServerCmdList(_ServerCmd):
 class _ServerCmdEnable(_ServerCmd):
     _NAME_OFFSET = 8
     _loglevel_struct = struct.Struct('>II')
+    # filter expression size
+    _filter_exp_len_struct = struct.Struct('>I')
 
-    def __init__(self, header, loglevel, loglevel_type, name):
+    def __init__(self, header, loglevel, loglevel_type, name, filter_exp):
         super(self.__class__, self).__init__(header)
         self.loglevel = loglevel
         self.loglevel_type = loglevel_type
         self.name = name
+        self.filter_expression = filter_exp
+        dbg._pdebug('server enable command {}'.format(self.__dict__))
 
     @classmethod
     def from_data(cls, header, data):
         try:
             loglevel, loglevel_type = cls._loglevel_struct.unpack_from(data)
-            data_name = data[cls._loglevel_struct.size:]
+            name_start = cls._loglevel_struct.size
+            name_end = name_start + _LTTNG_SYMBOL_NAME_LEN
+            data_name = data[name_start:name_end]
             name = data_name.rstrip(b'\0').decode()
 
-            return cls(header, loglevel, loglevel_type, name)
+            filter_exp_start = name_end + cls._filter_exp_len_struct.size
+            filter_exp_len, = cls._filter_exp_len_struct.unpack_from(
+                data[name_end:filter_exp_start])
+            print(filter_exp_len)
+            filter_exp_end = filter_exp_start + filter_exp_len
+
+            filter_exp = data[filter_exp_start:filter_exp_end].rstrip(
+                b'\0').decode()
+
+            return cls(header, loglevel, loglevel_type, name, filter_exp)
         except (Exception) as e:
             dbg._pdebug('cannot decode enable command: {}'.format(e))
             return None
-- 
2.6.2




More information about the lttng-dev mailing list