diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/examples/summaries/cocoa/metrics.py | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/examples/summaries/cocoa/metrics.py')
-rw-r--r-- | lldb/examples/summaries/cocoa/metrics.py | 168 |
1 files changed, 93 insertions, 75 deletions
diff --git a/lldb/examples/summaries/cocoa/metrics.py b/lldb/examples/summaries/cocoa/metrics.py index 6b82ff3b301..6a73a7344b9 100644 --- a/lldb/examples/summaries/cocoa/metrics.py +++ b/lldb/examples/summaries/cocoa/metrics.py @@ -6,89 +6,107 @@ This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. """ import lldb -import time, datetime +import time +import datetime import inspect + class TimeMetrics: - @staticmethod - def generate(label=None): - return TimeMetrics(label) - - def __init__(self,lbl=None): - self.label = "" if lbl is None else lbl - pass - - def __enter__(self): - caller = inspect.stack()[1] - self.function = str(caller) - self.enter_time = time.clock() - - def __exit__(self, a,b,c): - self.exit_time = time.clock() - print("It took " + str(self.exit_time - self.enter_time) + " time units to run through " + self.function + self.label) - return False + + @staticmethod + def generate(label=None): + return TimeMetrics(label) + + def __init__(self, lbl=None): + self.label = "" if lbl is None else lbl + pass + + def __enter__(self): + caller = inspect.stack()[1] + self.function = str(caller) + self.enter_time = time.clock() + + def __exit__(self, a, b, c): + self.exit_time = time.clock() + print("It took " + str(self.exit_time - self.enter_time) + + " time units to run through " + self.function + self.label) + return False + class Counter: - def __init__(self): - self.count = 0 - self.list = [] - def update(self,name): - self.count = self.count + 1 - # avoid getting the full dump of this ValueObject just to save its metrics - if isinstance(name,lldb.SBValue): - self.list.append(name.GetName()) - else: - self.list.append(str(name)) - def __str__(self): - return str(self.count) + " times, for items [" + str(self.list) + "]" + + def __init__(self): + self.count = 0 + self.list = [] + + def update(self, name): + self.count = self.count + 1 + # avoid getting the full dump of this ValueObject just to save its + # metrics + if isinstance(name, lldb.SBValue): + self.list.append(name.GetName()) + else: + self.list.append(str(name)) + + def __str__(self): + return str(self.count) + " times, for items [" + str(self.list) + "]" + class MetricsPrinter_Verbose: - def __init__(self,metrics): - self.metrics = metrics - def __str__(self): - string = "" - for key,value in self.metrics.metrics.items(): - string = string + "metric " + str(key) + ": " + str(value) + "\n" - return string + + def __init__(self, metrics): + self.metrics = metrics + + def __str__(self): + string = "" + for key, value in self.metrics.metrics.items(): + string = string + "metric " + str(key) + ": " + str(value) + "\n" + return string + class MetricsPrinter_Compact: - def __init__(self,metrics): - self.metrics = metrics - def __str__(self): - string = "" - for key,value in self.metrics.metrics.items(): - string = string + "metric " + str(key) + " was hit " + str(value.count) + " times\n" - return string + + def __init__(self, metrics): + self.metrics = metrics + + def __str__(self): + string = "" + for key, value in self.metrics.metrics.items(): + string = string + "metric " + \ + str(key) + " was hit " + str(value.count) + " times\n" + return string + class Metrics: - def __init__(self): - self.metrics = {} - - def add_metric(self,name): - self.metrics[name] = Counter() - - def metric_hit(self,metric,trigger): - self.metrics[metric].update(trigger) - - def __getitem__(self,key): - return self.metrics[key] - - def __getattr__(self,name): - if name == 'compact': - return MetricsPrinter_Compact(self) - if name == 'verbose': - return MetricsPrinter_Verbose(self) - raise AttributeError("%r object has no attribute %r" % - (type(self).__name__, name)) - - def __str__(self): - return str(self.verbose) - - def metric_success(self,metric): - total_count = 0 - metric_count = self[metric].count - for key,value in self.metrics.items(): - total_count = total_count + value.count - if total_count > 0: - return metric_count / float(total_count) - return 0 + + def __init__(self): + self.metrics = {} + + def add_metric(self, name): + self.metrics[name] = Counter() + + def metric_hit(self, metric, trigger): + self.metrics[metric].update(trigger) + + def __getitem__(self, key): + return self.metrics[key] + + def __getattr__(self, name): + if name == 'compact': + return MetricsPrinter_Compact(self) + if name == 'verbose': + return MetricsPrinter_Verbose(self) + raise AttributeError("%r object has no attribute %r" % + (type(self).__name__, name)) + + def __str__(self): + return str(self.verbose) + + def metric_success(self, metric): + total_count = 0 + metric_count = self[metric].count + for key, value in self.metrics.items(): + total_count = total_count + value.count + if total_count > 0: + return metric_count / float(total_count) + return 0 |