make trace output pretty patch by Aleksey Yeschenko; reviewed by jbellis for CASSANDRA-4852
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/8f46176e Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/8f46176e Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/8f46176e Branch: refs/heads/trunk Commit: 8f46176e988f1e05a6eb54d238ff7fb32ad0861b Parents: 0d10424 Author: Jonathan Ellis <[email protected]> Authored: Wed Oct 24 17:03:26 2012 -0500 Committer: Jonathan Ellis <[email protected]> Committed: Wed Oct 24 17:03:46 2012 -0500 ---------------------------------------------------------------------- bin/cqlsh | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/8f46176e/bin/cqlsh ---------------------------------------------------------------------- diff --git a/bin/cqlsh b/bin/cqlsh index 4229b81..0b0d6f8 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -106,7 +106,7 @@ if os.path.isdir(cqlshlibdir): sys.path.insert(0, cqlshlibdir) from cqlshlib import cqlhandling, cql3handling, pylexotron -from cqlshlib.displaying import (RED, BLUE, ANSI_RESET, COLUMN_NAME_COLORS, +from cqlshlib.displaying import (MAGENTA, RED, BLUE, ANSI_RESET, COLUMN_NAME_COLORS, FormattedValue, colorme) from cqlshlib.formatting import format_by_type from cqlshlib.util import trim_if_present @@ -1021,9 +1021,13 @@ class Shell(cmd.Cmd): return True def print_trace(self, session_id): - out = self.query_out - out.write('\nTracing session: %s\n\n' % session_id) - self.perform_statement_untraced("SELECT activity, source, source_elapsed FROM system_traces.events WHERE session_id = '%s'" % session_id) + self.writeresult('Tracing session: ', color=MAGENTA, newline=False) + self.writeresult(session_id) + self.writeresult('') + self.perform_statement_untraced("SELECT activity, event_id, source, source_elapsed " + "FROM system_traces.events " + "WHERE session_id = '%s'" % (session_id,), + decoder=TraceSchemaDecoder) # these next two functions are not guaranteed perfect; just checks if the # statement parses fully according to cqlsh's own understanding of the @@ -2644,6 +2648,22 @@ class ErrorHandlingSchemaDecoder(OverrideableSchemaDecoder): def value_decode_error(self, err, namebytes, valuebytes, expectedtype): return DecodeError(valuebytes, err, expectedtype, colname=namebytes) +class TraceSchemaDecoder(cql.decoders.SchemaDecoder): + def __init__(self, schema): + cql.decoders.SchemaDecoder.__init__(self, schema) + + def decode_metadata_and_type(self, namebytes): + # override event_id columnname and type. + if namebytes == 'event_id': + return u'timestamp', 'timestamp', cql.cqltypes.UTF8Type, cql.cqltypes.UTF8Type + return cql.decoders.SchemaDecoder.decode_metadata_and_type(self, namebytes) + + def decode_value(self, valbytes, vtype, colname): + if colname == 'timestamp': + millis = (UUID(bytes=valbytes).get_time() - 0x01b21dd213814000) / 10000 + s, ms = divmod(millis, 1000) + return time.strftime('%H:%M:%S', time.localtime(s)) + ',' + str(ms).rjust(3, '0') + return cql.decoders.SchemaDecoder.decode_value(self, valbytes, vtype, colname) def option_with_default(cparser_getter, section, option, default=None): try:
