summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-01-24 05:59:50 +0000
committerGerrit Code Review <review@openstack.org>2018-01-24 05:59:50 +0000
commit22c1a9920914d6d372de0f9d7de31ca095279cee (patch)
tree6c3179e3800d88682af2c2c319ad2a34490253a2
parent252c14633a9238f4ef36625da7f0730bd62bca1d (diff)
parent23ab27ad38b81a5e374ba7f7c8cadb83932701ab (diff)
downloadosprofiler-22c1a9920914d6d372de0f9d7de31ca095279cee.tar.gz
Merge "Add initial 'trace list' command"
-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