CLI: add trace info saving to session_info.json 18/160118/7
authorAlexander Aksenov <a.aksenov@samsung.com>
Mon, 13 Nov 2017 15:23:46 +0000 (18:23 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Wed, 15 Nov 2017 13:21:33 +0000 (16:21 +0300)
Change-Id: I0e647d5d9598823a23653250b35e6a271eaef24e
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
src/cli/swap_cli/swap.py

index 2f38cc7..044a6d4 100644 (file)
@@ -8,6 +8,7 @@ from . import handler
 from . import features_handler
 import os
 import errno
+import json
 
 
 class Client(object):
@@ -17,6 +18,8 @@ class Client(object):
 
     __VERSION = "0.0.1"
     __TRACE_FILE = "/trace.bin"
+    __SESSION_INFO_FILE = "session_info.json"
+    __DEV_KEY = "dev_for_energy_profiling"
 
     def __init__(self, target_conf):
         '''
@@ -38,6 +41,7 @@ class Client(object):
         self.__trace = None
         self.__handler = handler.MessageHandler()
         self.__outdir = None
+        self.__proto_ver = ""
         logging.basicConfig(format=log_fmt, level=log_level)
 
     def __connect(self):
@@ -61,6 +65,7 @@ class Client(object):
     def __get_api_map_list(self):
         # Get API map list
         ver = self.__commands.version()
+        self.__proto_ver = ver
         if ver == '3.0' or ver == 'no_version':
             res = self.__intr.pull("/usr/lib/da_api_map", self.__api_map_path)
             if res[0] == -1:
@@ -96,6 +101,16 @@ class Client(object):
             if e.errno != errno.EEXIST and not os.path.isdir(outdir):
                 raise
 
+    def __store_session_info(self, target_info):
+        store_info = {'device_num': len(target_info[self.__DEV_KEY]),
+                      'version': self.__proto_ver}
+        store_info.update(target_info)
+
+        json_info = json.dumps(store_info)
+        with open(os.path.join(self.__outdir, self.__SESSION_INFO_FILE), 'w') as f:
+            f.write(json_info)
+
+
 
     def get_version(self):
         '''
@@ -149,6 +164,7 @@ class Client(object):
 
         self.__trace.start(self.__net.ip, self.__net.port,
                            outdir + self.__TRACE_FILE, self.__handler)
+        self.__store_session_info(self.__commands.get_target_info())
         self.__commands.swap_inst_add()
         self.__commands.config()
         self.__commands.start()