2 Objective-C runtime wrapper for use by LLDB Python formatters
4 part of The LLVM Compiler Infrastructure
5 This file is distributed under the University of Illinois Open Source
6 License. See LICENSE.TXT for details.
17 def generate(label=None):
18 return TimeMetrics(label)
20 def __init__(self, lbl=None):
21 self.label = "" if lbl is None else lbl
25 caller = inspect.stack()[1]
26 self.function = str(caller)
27 self.enter_time = time.clock()
29 def __exit__(self, a, b, c):
30 self.exit_time = time.clock()
31 print("It took " + str(self.exit_time - self.enter_time) +
32 " time units to run through " + self.function + self.label)
42 def update(self, name):
43 self.count = self.count + 1
44 # avoid getting the full dump of this ValueObject just to save its
46 if isinstance(name, lldb.SBValue):
47 self.list.append(name.GetName())
49 self.list.append(str(name))
52 return str(self.count) + " times, for items [" + str(self.list) + "]"
55 class MetricsPrinter_Verbose:
57 def __init__(self, metrics):
58 self.metrics = metrics
62 for key, value in self.metrics.metrics.items():
63 string = string + "metric " + str(key) + ": " + str(value) + "\n"
67 class MetricsPrinter_Compact:
69 def __init__(self, metrics):
70 self.metrics = metrics
74 for key, value in self.metrics.metrics.items():
75 string = string + "metric " + \
76 str(key) + " was hit " + str(value.count) + " times\n"
85 def add_metric(self, name):
86 self.metrics[name] = Counter()
88 def metric_hit(self, metric, trigger):
89 self.metrics[metric].update(trigger)
91 def __getitem__(self, key):
92 return self.metrics[key]
94 def __getattr__(self, name):
96 return MetricsPrinter_Compact(self)
98 return MetricsPrinter_Verbose(self)
99 raise AttributeError("%r object has no attribute %r" %
100 (type(self).__name__, name))
103 return str(self.verbose)
105 def metric_success(self, metric):
107 metric_count = self[metric].count
108 for key, value in self.metrics.items():
109 total_count = total_count + value.count
111 return metric_count / float(total_count)