Lines Matching refs:self

13   def ToPerfJson(self) -> str:
17 def ToPython(self) -> str:
21 def Simplify(self):
22 """Returns a simplified version of self."""
25 def Equals(self, other) -> bool:
29 def Substitute(self, name: str, expression: 'Expression') -> 'Expression':
32 def __str__(self) -> str:
33 return self.ToPerfJson()
35 def __or__(self, other: Union[int, float, 'Expression']) -> 'Operator':
36 return Operator('|', self, other)
38 def __ror__(self, other: Union[int, float, 'Expression']) -> 'Operator':
39 return Operator('|', other, self)
41 def __xor__(self, other: Union[int, float, 'Expression']) -> 'Operator':
42 return Operator('^', self, other)
44 def __and__(self, other: Union[int, float, 'Expression']) -> 'Operator':
45 return Operator('&', self, other)
47 def __rand__(self, other: Union[int, float, 'Expression']) -> 'Operator':
48 return Operator('&', other, self)
50 def __lt__(self, other: Union[int, float, 'Expression']) -> 'Operator':
51 return Operator('<', self, other)
53 def __gt__(self, other: Union[int, float, 'Expression']) -> 'Operator':
54 return Operator('>', self, other)
56 def __add__(self, other: Union[int, float, 'Expression']) -> 'Operator':
57 return Operator('+', self, other)
59 def __radd__(self, other: Union[int, float, 'Expression']) -> 'Operator':
60 return Operator('+', other, self)
62 def __sub__(self, other: Union[int, float, 'Expression']) -> 'Operator':
63 return Operator('-', self, other)
65 def __rsub__(self, other: Union[int, float, 'Expression']) -> 'Operator':
66 return Operator('-', other, self)
68 def __mul__(self, other: Union[int, float, 'Expression']) -> 'Operator':
69 return Operator('*', self, other)
71 def __rmul__(self, other: Union[int, float, 'Expression']) -> 'Operator':
72 return Operator('*', other, self)
74 def __truediv__(self, other: Union[int, float, 'Expression']) -> 'Operator':
75 return Operator('/', self, other)
77 def __rtruediv__(self, other: Union[int, float, 'Expression']) -> 'Operator':
78 return Operator('/', other, self)
80 def __mod__(self, other: Union[int, float, 'Expression']) -> 'Operator':
81 return Operator('%', self, other)
115 def __init__(self, operator: str, lhs: Union[int, float, Expression],
117 self.operator = operator
118 self.lhs = _Constify(lhs)
119 self.rhs = _Constify(rhs)
121 def Bracket(self,
128 this/self operator has higher precedence. Consider: '(a + b) * c',
145 if _PRECEDENCE.get(self.operator, -1) > _PRECEDENCE.get(
148 if rhs and _PRECEDENCE.get(self.operator, -1) == _PRECEDENCE.get(
153 def ToPerfJson(self):
154 return (f'{self.Bracket(self.lhs, self.lhs.ToPerfJson())} {self.operator} '
155 f'{self.Bracket(self.rhs, self.rhs.ToPerfJson(), True)}')
157 def ToPython(self):
158 return (f'{self.Bracket(self.lhs, self.lhs.ToPython())} {self.operator} '
159 f'{self.Bracket(self.rhs, self.rhs.ToPython(), True)}')
161 def Simplify(self) -> Expression:
162 lhs = self.lhs.Simplify()
163 rhs = self.rhs.Simplify()
165 return Constant(ast.literal_eval(lhs + self.operator + rhs))
167 if isinstance(self.lhs, Constant):
168 if self.operator in ('+', '|') and lhs.value == '0':
173 if self.operator == '*' and lhs.value == '0' and (
177 if self.operator == '*' and lhs.value == '1':
181 if self.operator in ('+', '|') and rhs.value == '0':
184 if self.operator == '*' and rhs.value == '0':
187 if self.operator == '*' and self.rhs.value == '1':
190 return Operator(self.operator, lhs, rhs)
192 def Equals(self, other: Expression) -> bool:
194 return self.operator == other.operator and self.lhs.Equals(
195 other.lhs) and self.rhs.Equals(other.rhs)
198 def Substitute(self, name: str, expression: Expression) -> Expression:
199 if self.Equals(expression):
201 lhs = self.lhs.Substitute(name, expression)
203 if self.rhs:
204 rhs = self.rhs.Substitute(name, expression)
205 return Operator(self.operator, lhs, rhs)
211 def __init__(self, true_val: Union[int, float, Expression],
214 self.true_val = _Constify(true_val)
215 self.cond = _Constify(cond)
216 self.false_val = _Constify(false_val)
218 def ToPerfJson(self):
219 true_str = self.true_val.ToPerfJson()
220 cond_str = self.cond.ToPerfJson()
221 false_str = self.false_val.ToPerfJson()
224 def ToPython(self):
225 return (f'Select({self.true_val.ToPython()}, {self.cond.ToPython()}, '
226 f'{self.false_val.ToPython()})')
228 def Simplify(self) -> Expression:
229 cond = self.cond.Simplify()
230 true_val = self.true_val.Simplify()
231 false_val = self.false_val.Simplify()
240 def Equals(self, other: Expression) -> bool:
242 return self.cond.Equals(other.cond) and self.false_val.Equals(
243 other.false_val) and self.true_val.Equals(other.true_val)
246 def Substitute(self, name: str, expression: Expression) -> Expression:
247 if self.Equals(expression):
249 true_val = self.true_val.Substitute(name, expression)
250 cond = self.cond.Substitute(name, expression)
251 false_val = self.false_val.Substitute(name, expression)
258 def __init__(self,
262 self.fn = fn
263 self.lhs = _Constify(lhs)
264 self.rhs = _Constify(rhs)
266 def ToPerfJson(self):
267 if self.rhs:
268 return f'{self.fn}({self.lhs.ToPerfJson()}, {self.rhs.ToPerfJson()})'
269 return f'{self.fn}({self.lhs.ToPerfJson()})'
271 def ToPython(self):
272 if self.rhs:
273 return f'{self.fn}({self.lhs.ToPython()}, {self.rhs.ToPython()})'
274 return f'{self.fn}({self.lhs.ToPython()})'
276 def Simplify(self) -> Expression:
277 lhs = self.lhs.Simplify()
278 rhs = self.rhs.Simplify() if self.rhs else None
280 if self.fn == 'd_ratio':
284 return Constant(ast.literal_eval(f'{self.fn}({lhs}, {rhs})'))
286 return Function(self.fn, lhs, rhs)
288 def Equals(self, other: Expression) -> bool:
290 result = self.fn == other.fn and self.lhs.Equals(other.lhs)
291 if self.rhs:
292 result = result and self.rhs.Equals(other.rhs)
296 def Substitute(self, name: str, expression: Expression) -> Expression:
297 if self.Equals(expression):
299 lhs = self.lhs.Substitute(name, expression)
301 if self.rhs:
302 rhs = self.rhs.Substitute(name, expression)
303 return Function(self.fn, lhs, rhs)
314 def __init__(self, name: str, legacy_name: str = ''):
315 self.name = _FixEscapes(name)
316 self.legacy_name = _FixEscapes(legacy_name)
318 def ToPerfJson(self):
319 result = re.sub('/', '@', self.name)
322 def ToPython(self):
323 return f'Event(r"{self.name}")'
325 def Simplify(self) -> Expression:
326 return self
328 def Equals(self, other: Expression) -> bool:
329 return isinstance(other, Event) and self.name == other.name
331 def Substitute(self, name: str, expression: Expression) -> Expression:
332 return self
338 def __init__(self, value: Union[float, str]):
342 self.value = dec.normalize().to_eng_string()
343 self.value = self.value.replace('+', '')
344 self.value = self.value.replace('E', 'e')
346 def ToPerfJson(self):
347 return self.value
349 def ToPython(self):
350 return f'Constant({self.value})'
352 def Simplify(self) -> Expression:
353 return self
355 def Equals(self, other: Expression) -> bool:
356 return isinstance(other, Constant) and self.value == other.value
358 def Substitute(self, name: str, expression: Expression) -> Expression:
359 return self
365 def __init__(self, value: str):
366 self.value = value
368 def ToPerfJson(self):
369 return self.value
371 def ToPython(self):
372 return f'Literal({self.value})'
374 def Simplify(self) -> Expression:
375 return self
377 def Equals(self, other: Expression) -> bool:
378 return isinstance(other, Literal) and self.value == other.value
380 def Substitute(self, name: str, expression: Expression) -> Expression:
381 return self
428 def __init__(self,
434 self.name = name
435 self.description = description
436 self.expr = expr.Simplify()
440 self.scale_unit = scale_unit
442 self.scale_unit = f'1{scale_unit}'
443 self.constraint = constraint
444 self.groups = set()
446 def __lt__(self, other):
448 return self.name < other.name
450 def AddToMetricGroup(self, group):
452 self.groups.add(group.name)
454 def Flatten(self) -> Set['Metric']:
456 return set([self])
458 def ToPerfJson(self) -> Dict[str, str]:
461 'MetricName': self.name,
462 'MetricGroup': ';'.join(sorted(self.groups)),
463 'BriefDescription': self.description,
464 'MetricExpr': self.expr.ToPerfJson(),
465 'ScaleUnit': self.scale_unit
467 if self.constraint:
476 def default(self, o):
479 return json.JSONEncoder.default(self, o)
490 def __init__(self, name: str, metric_list: List[Union[Metric,
492 self.name = name
493 self.metric_list = metric_list
495 metric.AddToMetricGroup(self)
497 def AddToMetricGroup(self, group):
499 for metric in self.metric_list:
502 def Flatten(self) -> Set[Metric]:
505 for x in self.metric_list:
510 def ToPerfJson(self) -> str:
511 return json.dumps(sorted(self.Flatten()), indent=2, cls=_MetricJsonEncoder)
513 def __str__(self) -> str:
514 return self.ToPerfJson()
520 def visit_IfExp(self, node):
522 self.generic_visit(node)