From 0af8a6bee177f307106426760e269a99a876883b Mon Sep 17 00:00:00 2001 From: Jeremiah Johnson Date: Thu, 20 Aug 2015 09:40:32 -0600 Subject: [PATCH 1/2] show duration on success - track start time when thread starts - calculate duration when thread completes - show duration in seconds on success Test Plan: tested in my local environment for several days --- lib/cli.py | 5 ++++- lib/response_handler.py | 8 +++++++- lib/threads.py | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 3002115..64429aa 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -48,6 +48,7 @@ def call(operation, use_mm_panel=True, **kwargs): context=kwargs.get('context', None), message=kwargs.get('message', None), use_mm_panel=use_mm_panel, + start_time=time.time(), process_id=util.get_random_string(10), callback=kwargs.get('callback', None), flags=kwargs.get('flags', None) @@ -70,6 +71,7 @@ def __init__(self, operation, **kwargs): self.view = None self.window = None self.printer = None + self.start_time = time.time() self.process_id = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) self.use_mm_panel = kwargs.get('use_mm_panel', False) self.result = None #result of operation @@ -192,11 +194,12 @@ def run(self): ThreadTracker.remove(self) #handles the result of the mm script -def handle_result(operation, process_id, printer, res, thread): +def handle_result(operation, process_id, start_time, printer, res, thread): try: context = { "operation" : operation, "process_id" : process_id, + "start_time" : start_time, "printer" : printer, "response" : res, "thread" : thread diff --git a/lib/response_handler.py b/lib/response_handler.py index 1a0da92..17d1175 100644 --- a/lib/response_handler.py +++ b/lib/response_handler.py @@ -3,6 +3,7 @@ import os import sys import html.parser +import time import traceback from .merge import MavensMateDiffThread import MavensMate.util as util @@ -17,11 +18,15 @@ class MavensMateResponseHandler(object): def __init__(self, context): self.operation = context.get('operation', None) self.process_id = context.get('process_id', None) + self.start_time = context.get('start_time', None) + self.duration = 0 self.printer = context.get('printer', None) self.thread = context.get('thread', None) self.response = context.get('response', None) self.process_region = self.printer.panel.find(self.process_id,0) self.status_region = self.printer.panel.find(' Result: ',self.process_region.begin()) + if self.start_time is not None: + self.duration = time.time() - self.start_time try: self.response = json.loads(self.response) @@ -255,7 +260,8 @@ def __handle_compile_response(self, **kwargs): success = self.response['result']['success'] if success: util.clear_marked_line_numbers(self.thread.view) - self.__print_to_panel("Success") + msg = "Success, %.1fs" % self.duration + self.__print_to_panel(msg) self.printer.hide() return diff --git a/lib/threads.py b/lib/threads.py index 24e963a..748ca60 100644 --- a/lib/threads.py +++ b/lib/threads.py @@ -112,7 +112,7 @@ def run(self, i): if not self.thread.is_alive(): if hasattr(self.thread, 'result'): #thread is done, we need to handle the result - self.thread.callback(self.thread.operation, self.thread.process_id, self.thread.printer, self.thread.result, self.thread) + self.thread.callback(self.thread.operation, self.thread.process_id, self.thread.start_time, self.thread.printer, self.thread.result, self.thread) if self.thread.alt_callback != None: self.thread.alt_callback(self.thread.context) #self.thread.printer.panel.run_command('write_operation_status', {'text': self.thread.result, 'region': [self.thread.status_region.end(), self.thread.status_region.end()+10] }) From 784b4a6019aa0ca16a6a7f0783a5e0b7e043e6a2 Mon Sep 17 00:00:00 2001 From: Jeremiah Johnson Date: Thu, 20 Aug 2015 12:02:40 -0600 Subject: [PATCH 2/2] pull start_time from kwargs, if available --- lib/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index 64429aa..105dc2b 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -71,7 +71,7 @@ def __init__(self, operation, **kwargs): self.view = None self.window = None self.printer = None - self.start_time = time.time() + self.start_time = kwargs.get('start_time', time.time()) self.process_id = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) self.use_mm_panel = kwargs.get('use_mm_panel', False) self.result = None #result of operation