summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmer Anson <omer.anson@toganetworks.com>2017-11-19 23:50:42 +0200
committerIlya Shakhat <shakhat@gmail.com>2018-01-23 13:31:04 +0100
commit23ab27ad38b81a5e374ba7f7c8cadb83932701ab (patch)
tree74d23c885699f2012f560044e15346863aff0dff
parent0bb909c7a039f17b957d920c93d366d89e581280 (diff)
downloadosprofiler-23ab27ad38b81a5e374ba7f7c8cadb83932701ab.tar.gz
Add initial 'trace list' command
This is an initial trace list command, which acts both as a starting-point, as well as an immediate solution for anyone who needs the basic functionality of this feature. Change-Id: I99ad62103914b047cfc3c33e50ae98b6a0d01d6d Related-Bug: #1733232
-rw-r--r--osprofiler/cmd/commands.py26
-rw-r--r--requirements.txt1
2 files changed, 27 insertions, 0 deletions
diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py
index 67aaa43..870b653 100644
--- a/osprofiler/cmd/commands.py
+++ b/osprofiler/cmd/commands.py
@@ -15,7 +15,10 @@
import json
import os
+import prettytable
+import six
+from oslo_utils import encodeutils
from oslo_utils import uuidutils
from osprofiler.cmd import cliutils
@@ -150,3 +153,26 @@ class TraceCommands(BaseCommand):
_create_sub_graph(trace)
return dot
+
+ @cliutils.arg("--connection-string", dest="conn_str",
+ default=(cliutils.env("OSPROFILER_CONNECTION_STRING")),
+ required=True,
+ help="Storage driver's connection string. Defaults to "
+ "env[OSPROFILER_CONNECTION_STRING] if set")
+ def list(self, args):
+ try:
+ engine = base.get_driver(args.conn_str, **args.__dict__)
+ except Exception as e:
+ raise exc.CommandError(e.message)
+
+ fields = ("base_id", "timestamp")
+ pretty_table = prettytable.PrettyTable(fields)
+ pretty_table.align = "l"
+ traces = engine.list_traces({}, fields)
+ for trace in traces:
+ row = [trace[field] for field in fields]
+ pretty_table.add_row(row)
+ if six.PY3:
+ print(encodeutils.safe_encode(pretty_table.get_string()).decode())
+ else:
+ print(encodeutils.safe_encode(pretty_table.get_string()))
diff --git a/requirements.txt b/requirements.txt
index 29c9200..0a26c58 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ requests>=2.10.0 # Apache-2.0
netaddr>=0.7.13,!=0.7.16 # BSD
oslo.concurrency>=3.8.0 # Apache-2.0
oslo.serialization>=2.18.0,!=2.19.1 # Apache-2.0
+PrettyTable>=0.7.1,<0.8 # BSD