Renamed internal script result types * -> R*

So Int -> RInt, Frac -> RFrac, etc. This just helps distinguish these
types from builtin types, which could be confusing.
This commit is contained in:
Christopher Haster
2024-05-13 15:08:03 -05:00
parent 03ea2e6ac5
commit a9f6b6e903
8 changed files with 71 additions and 68 deletions
+4 -4
View File
@@ -29,10 +29,10 @@ OBJDUMP_PATH = ['objdump']
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -110,12 +110,12 @@ class CodeResult(co.namedtuple('CodeResult', [
_by = ['file', 'function']
_fields = ['size']
_sort = ['size']
_types = {'size': Int}
_types = {'size': RInt}
__slots__ = ()
def __new__(cls, file='', function='', size=0):
return super().__new__(cls, file, function,
Int(size))
RInt(size))
def __add__(self, other):
return CodeResult(self.file, self.function,
+17 -16
View File
@@ -29,10 +29,10 @@ GCOV_PATH = ['gcov']
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -104,16 +104,16 @@ class Int(co.namedtuple('Int', 'x')):
return self.__class__(self.x * other.x)
# fractional fields, a/b
class Frac(co.namedtuple('Frac', 'a,b')):
class RFrac(co.namedtuple('RFrac', 'a,b')):
__slots__ = ()
def __new__(cls, a=0, b=None):
if isinstance(a, Frac) and b is None:
if isinstance(a, RFrac) and b is None:
return a
if isinstance(a, str) and b is None:
a, b = a.split('/', 1)
if b is None:
b = a
return super().__new__(cls, Int(a), Int(b))
return super().__new__(cls, RInt(a), RInt(b))
def __str__(self):
return '%s/%s' % (self.a, self.b)
@@ -132,15 +132,15 @@ class Frac(co.namedtuple('Frac', 'a,b')):
else '%.1f%%' % (100*t)]
def diff(self, other):
new_a, new_b = self if self else (Int(0), Int(0))
old_a, old_b = other if other else (Int(0), Int(0))
new_a, new_b = self if self else (RInt(0), RInt(0))
old_a, old_b = other if other else (RInt(0), RInt(0))
return '%11s' % ('%s/%s' % (
new_a.diff(old_a).strip(),
new_b.diff(old_b).strip()))
def ratio(self, other):
new_a, new_b = self if self else (Int(0), Int(0))
old_a, old_b = other if other else (Int(0), Int(0))
new_a, new_b = self if self else (RInt(0), RInt(0))
old_a, old_b = other if other else (RInt(0), RInt(0))
new = new_a.x/new_b.x if new_b.x else 1.0
old = old_a.x/old_b.x if old_b.x else 1.0
return new - old
@@ -176,14 +176,15 @@ class CovResult(co.namedtuple('CovResult', [
_fields = ['calls', 'hits', 'funcs', 'lines', 'branches']
_sort = ['funcs', 'lines', 'branches', 'hits', 'calls']
_types = {
'calls': Int, 'hits': Int,
'funcs': Frac, 'lines': Frac, 'branches': Frac}
'calls': RInt, 'hits': RInt,
'funcs': RFrac, 'lines': RFrac, 'branches': RFrac}
__slots__ = ()
def __new__(cls, file='', function='', line=0,
calls=0, hits=0, funcs=0, lines=0, branches=0):
return super().__new__(cls, file, function, int(Int(line)),
Int(calls), Int(hits), Frac(funcs), Frac(lines), Frac(branches))
return super().__new__(cls, file, function, int(RInt(line)),
RInt(calls), RInt(hits),
RFrac(funcs), RFrac(lines), RFrac(branches))
def __add__(self, other):
return CovResult(self.file, self.function, self.line,
@@ -265,7 +266,7 @@ def collect(gcda_paths, *,
results.append(CovResult(
file_name, func_name, func['start_line'],
func['execution_count'], 0,
Frac(1 if func['execution_count'] > 0 else 0, 1),
RFrac(1 if func['execution_count'] > 0 else 0, 1),
0,
0))
@@ -282,8 +283,8 @@ def collect(gcda_paths, *,
file_name, func_name, line['line_number'],
0, line['count'],
0,
Frac(1 if line['count'] > 0 else 0, 1),
Frac(
RFrac(1 if line['count'] > 0 else 0, 1),
RFrac(
sum(1 if branch['count'] > 0 else 0
for branch in line['branches']),
len(line['branches']))))
+4 -4
View File
@@ -29,10 +29,10 @@ OBJDUMP_PATH = ['objdump']
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -110,12 +110,12 @@ class DataResult(co.namedtuple('DataResult', [
_by = ['file', 'function']
_fields = ['size']
_sort = ['size']
_types = {'size': Int}
_types = {'size': RInt}
__slots__ = ()
def __new__(cls, file='', function='', size=0):
return super().__new__(cls, file, function,
Int(size))
RInt(size))
def __add__(self, other):
return DataResult(self.file, self.function,
+9 -7
View File
@@ -38,10 +38,10 @@ THRESHOLD = (0.5, 0.85)
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -121,16 +121,18 @@ class PerfResult(co.namedtuple('PerfResult', [
_fields = ['cycles', 'bmisses', 'branches', 'cmisses', 'caches']
_sort = ['cycles', 'bmisses', 'cmisses', 'branches', 'caches']
_types = {
'cycles': Int,
'bmisses': Int, 'branches': Int,
'cmisses': Int, 'caches': Int}
'cycles': RInt,
'bmisses': RInt, 'branches': RInt,
'cmisses': RInt, 'caches': RInt}
__slots__ = ()
def __new__(cls, file='', function='', line=0,
cycles=0, bmisses=0, branches=0, cmisses=0, caches=0,
children=[]):
return super().__new__(cls, file, function, int(Int(line)),
Int(cycles), Int(bmisses), Int(branches), Int(cmisses), Int(caches),
return super().__new__(cls, file, function, int(RInt(line)),
RInt(cycles),
RInt(bmisses), RInt(branches),
RInt(cmisses), RInt(caches),
children)
def __add__(self, other):
+5 -5
View File
@@ -29,10 +29,10 @@ THRESHOLD = (0.5, 0.85)
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -111,14 +111,14 @@ class PerfBdResult(co.namedtuple('PerfBdResult', [
_by = ['file', 'function', 'line']
_fields = ['readed', 'proged', 'erased']
_sort = ['erased', 'proged', 'readed']
_types = {'readed': Int, 'proged': Int, 'erased': Int}
_types = {'readed': RInt, 'proged': RInt, 'erased': RInt}
__slots__ = ()
def __new__(cls, file='', function='', line=0,
readed=0, proged=0, erased=0,
children=[]):
return super().__new__(cls, file, function, int(Int(line)),
Int(readed), Int(proged), Int(erased),
return super().__new__(cls, file, function, int(RInt(line)),
RInt(readed), RInt(proged), RInt(erased),
children)
def __add__(self, other):
+4 -4
View File
@@ -20,10 +20,10 @@ import re
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -100,13 +100,13 @@ class StackResult(co.namedtuple('StackResult', [
_by = ['file', 'function']
_fields = ['frame', 'limit']
_sort = ['limit', 'frame']
_types = {'frame': Int, 'limit': Int}
_types = {'frame': RInt, 'limit': RInt}
__slots__ = ()
def __new__(cls, file='', function='',
frame=0, limit=0, children=set()):
return super().__new__(cls, file, function,
Int(frame), Int(limit),
RInt(frame), RInt(limit),
children)
def __add__(self, other):
+4 -4
View File
@@ -25,10 +25,10 @@ OBJDUMP_PATH = ['objdump']
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -104,12 +104,12 @@ class StructResult(co.namedtuple('StructResult', ['file', 'struct', 'size'])):
_by = ['file', 'struct']
_fields = ['size']
_sort = ['size']
_types = {'size': Int}
_types = {'size': RInt}
__slots__ = ()
def __new__(cls, file='', struct='', size=0):
return super().__new__(cls, file, struct,
Int(size))
RInt(size))
def __add__(self, other):
return StructResult(self.file, self.struct,
+24 -24
View File
@@ -30,14 +30,14 @@ OPS = {
'prod': lambda xs: m.prod(xs[1:], start=xs[0]),
'min': min,
'max': max,
'avg': lambda xs: Float(sum(float(x) for x in xs) / len(xs)),
'avg': lambda xs: RFloat(sum(float(x) for x in xs) / len(xs)),
'stddev': lambda xs: (
lambda avg: Float(
lambda avg: RFloat(
m.sqrt(sum((float(x) - avg)**2 for x in xs) / len(xs)))
)(sum(float(x) for x in xs) / len(xs)),
'gmean': lambda xs: Float(m.prod(float(x) for x in xs)**(1/len(xs))),
'gmean': lambda xs: RFloat(m.prod(float(x) for x in xs)**(1/len(xs))),
'gstddev': lambda xs: (
lambda gmean: Float(
lambda gmean: RFloat(
m.exp(m.sqrt(sum(m.log(float(x)/gmean)**2 for x in xs) / len(xs)))
if gmean else m.inf)
)(m.prod(float(x) for x in xs)**(1/len(xs))),
@@ -45,10 +45,10 @@ OPS = {
# integer fields
class Int(co.namedtuple('Int', 'x')):
class RInt(co.namedtuple('RInt', 'x')):
__slots__ = ()
def __new__(cls, x=0):
if isinstance(x, Int):
if isinstance(x, RInt):
return x
if isinstance(x, str):
try:
@@ -120,10 +120,10 @@ class Int(co.namedtuple('Int', 'x')):
return self.__class__(self.x * other.x)
# float fields
class Float(co.namedtuple('Float', 'x')):
class RFloat(co.namedtuple('RFloat', 'x')):
__slots__ = ()
def __new__(cls, x=0.0):
if isinstance(x, Float):
if isinstance(x, RFloat):
return x
if isinstance(x, str):
try:
@@ -150,8 +150,8 @@ class Float(co.namedtuple('Float', 'x')):
def __float__(self):
return float(self.x)
none = Int.none
table = Int.table
none = RInt.none
table = RInt.table
def diff(self, other):
new = self.x if self else 0
@@ -164,22 +164,22 @@ class Float(co.namedtuple('Float', 'x')):
else:
return '%+7.1f' % diff
ratio = Int.ratio
__add__ = Int.__add__
__sub__ = Int.__sub__
__mul__ = Int.__mul__
ratio = RInt.ratio
__add__ = RInt.__add__
__sub__ = RInt.__sub__
__mul__ = RInt.__mul__
# fractional fields, a/b
class Frac(co.namedtuple('Frac', 'a,b')):
class RFrac(co.namedtuple('RFrac', 'a,b')):
__slots__ = ()
def __new__(cls, a=0, b=None):
if isinstance(a, Frac) and b is None:
if isinstance(a, RFrac) and b is None:
return a
if isinstance(a, str) and b is None:
a, b = a.split('/', 1)
if b is None:
b = a
return super().__new__(cls, Int(a), Int(b))
return super().__new__(cls, RInt(a), RInt(b))
def __str__(self):
return '%s/%s' % (self.a, self.b)
@@ -198,15 +198,15 @@ class Frac(co.namedtuple('Frac', 'a,b')):
else '%.1f%%' % (100*t)]
def diff(self, other):
new_a, new_b = self if self else (Int(0), Int(0))
old_a, old_b = other if other else (Int(0), Int(0))
new_a, new_b = self if self else (RInt(0), RInt(0))
old_a, old_b = other if other else (RInt(0), RInt(0))
return '%11s' % ('%s/%s' % (
new_a.diff(old_a).strip(),
new_b.diff(old_b).strip()))
def ratio(self, other):
new_a, new_b = self if self else (Int(0), Int(0))
old_a, old_b = other if other else (Int(0), Int(0))
new_a, new_b = self if self else (RInt(0), RInt(0))
old_a, old_b = other if other else (RInt(0), RInt(0))
new = new_a.x/new_b.x if new_b.x else 1.0
old = old_a.x/old_b.x if old_b.x else 1.0
return new - old
@@ -236,9 +236,9 @@ class Frac(co.namedtuple('Frac', 'a,b')):
# available types
TYPES = co.OrderedDict([
('int', Int),
('float', Float),
('frac', Frac)
('int', RInt),
('float', RFloat),
('frac', RFrac)
])