Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry/enable app insights [Finished #114911063] #33

Merged
merged 10 commits into from
Mar 11, 2016
Prev Previous commit
Next Next commit
update perf timer usage
  • Loading branch information
BurtBiel committed Mar 4, 2016
commit 42de26c214650d6ce83eb0cd3f5765b2ba507c79
7 changes: 3 additions & 4 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ def not_global(a):
old_stdout = sys.stdout
try:
sys.stdout = out
with PerfTimer():
result = handler(parsed, others)
telemetry_log_event("Command Finished", {"CommandName": " ".join(nouns)},
{"ExecutionTime": PerfTimer.last_measured_milliseconds()})
p = PerfTimer("Command Execution", {"CommandName": " ".join(nouns)})
result = handler(parsed, others)
p.store_perf_data()
return result
except IncorrectUsageError as ex:
telemetry_log_event("Incorrect Usage", {"CommandName": " ".join(nouns)})
Expand Down
25 changes: 10 additions & 15 deletions src/azure/cli/_performance.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import time
from ._telemetry import telemetry_log_performance

class PerfTimer(object): # pylint:disable=too-few-public-methods
_last_result = 0

def __init__(self, *args, **kwargs):
def __init__(self, event_name, properties):
self.event_name = event_name
self.properties = properties
self.start = 0
self.end = 0
super(PerfTimer, self).__init__(*args, **kwargs)

def __enter__(self):
self.start = time.time()
return self
super(PerfTimer, self).__init__()

def __exit__(self, *args):
self.end = time.time()
PerfTimer._last_result = (self.end - self.start) * 1000
def total_milliseconds(self):
return (time.time() - self.start) * 1000

@staticmethod
def last_measured_milliseconds():
return PerfTimer._last_result
def store_perf_data(self):
self.properties["Milliseconds"] = self.total_milliseconds()
telemetry_log_performance(self.event_name, self.properties)
2 changes: 2 additions & 0 deletions src/azure/cli/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ def telemetry_log_event(name, properties=None, measurements=None):
#pass
raise e

def telemetry_log_performance(name, properties=None):
telemetry_log_event("Perf: "+name, properties)