Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3CF3F200B24 for ; Wed, 18 May 2016 03:03:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3AFB5160A24; Wed, 18 May 2016 01:03:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8A3B8160A1F for ; Wed, 18 May 2016 03:03:16 +0200 (CEST) Received: (qmail 94042 invoked by uid 500); 18 May 2016 01:03:15 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 93989 invoked by uid 99); 18 May 2016 01:03:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 01:03:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5A719DFDCF; Wed, 18 May 2016 01:03:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stefania@apache.org To: commits@cassandra.apache.org Date: Wed, 18 May 2016 01:03:16 -0000 Message-Id: <09944ba203024182b588a9e5d25010fc@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [02/10] cassandra git commit: Add seconds to cqlsh tracing session duration archived-at: Wed, 18 May 2016 01:03:17 -0000 Add seconds to cqlsh tracing session duration patch by Stefania Alborghetti; reviewed by Tyler Hobbs for CASSANDRA-11753 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e8e917ff Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e8e917ff Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e8e917ff Branch: refs/heads/cassandra-3.0 Commit: e8e917ff9fa47fd48b85f4cc767a61bf297b3225 Parents: 330d7d4 Author: Stefania Alborghetti Authored: Mon May 16 11:00:29 2016 +0800 Committer: Stefania Alborghetti Committed: Wed May 18 08:52:43 2016 +0800 ---------------------------------------------------------------------- CHANGES.txt | 1 + pylib/cqlshlib/tracing.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/e8e917ff/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index dfcad10..befb520 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ * Fix commit log replay after out-of-order flush completion (CASSANDRA-9669) 2.2.7 + * Add seconds to cqlsh tracing session duration (CASSANDRA-11753) * Prohibit Reverse Counter type as part of the PK (CASSANDRA-9395) * cqlsh: correctly handle non-ascii chars in error messages (CASSANDRA-11626) * Exit JVM if JMX server fails to startup (CASSANDRA-11540) http://git-wip-us.apache.org/repos/asf/cassandra/blob/e8e917ff/pylib/cqlshlib/tracing.py ---------------------------------------------------------------------- diff --git a/pylib/cqlshlib/tracing.py b/pylib/cqlshlib/tracing.py index 2ded259..c30965c 100644 --- a/pylib/cqlshlib/tracing.py +++ b/pylib/cqlshlib/tracing.py @@ -15,7 +15,7 @@ # limitations under the License. from cqlshlib.displaying import MAGENTA -from datetime import datetime +from datetime import datetime, timedelta import time from cassandra.query import QueryTrace, TraceUnavailable @@ -66,17 +66,24 @@ def make_trace_rows(trace): rows.append(["%s [%s]" % (event.description, event.thread_name), str(datetime_from_utc_to_local(event.datetime)), event.source, - event.source_elapsed.microseconds if event.source_elapsed else "--"]) + total_micro_seconds(event.source_elapsed)]) # append footer row (from sessions table). if trace.duration: finished_at = (datetime_from_utc_to_local(trace.started_at) + trace.duration) - rows.append(['Request complete', str(finished_at), trace.coordinator, trace.duration.microseconds]) + rows.append(['Request complete', str(finished_at), trace.coordinator, total_micro_seconds(trace.duration)]) else: finished_at = trace.duration = "--" return rows +def total_micro_seconds(td): + """ + Convert a timedelta into total microseconds + """ + return int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)) if td else "--" + + def datetime_from_utc_to_local(utc_datetime): now_timestamp = time.time() offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp)