ATLAS Offline Software
Loading...
Searching...
No Matches
python.trfUtils.analytic Class Reference

Analytics service class. More...

Collaboration diagram for python.trfUtils.analytic:

Public Member Functions

 __init__ (self, **kwargs)
 fit (self, x, y, model='linear')
 Fitting function For a linear model: y(x) = slope * x + intersect.
 slope (self)
 getFittedData (self, filename, x_name='Time', y_name='pss', precision=2, tails=False, minPoints=5)
 extractFromTable (self, table, x_name, y_name)
 formatBytes (self, size)

Static Protected Attributes

 _fit = None

Detailed Description

Analytics service class.

Definition at line 1263 of file trfUtils.py.

Constructor & Destructor Documentation

◆ __init__()

python.trfUtils.analytic.__init__ ( self,
** kwargs )

Definition at line 1267 of file trfUtils.py.

1267 def __init__(self, **kwargs):
1268 self._fit = None
1269

Member Function Documentation

◆ extractFromTable()

python.trfUtils.analytic.extractFromTable ( self,
table,
x_name,
y_name )

Definition at line 1346 of file trfUtils.py.

1346 def extractFromTable(self, table, x_name, y_name):
1347 headerUpperVersion = {'pss':'PSS', 'swap':'Swap', 'rss':'RSS', 'vmem':'VMEM'}
1348 x = table.get(x_name, [])
1349 if '+' not in y_name:
1350 y = table.get(y_name, [])
1351 if len(y)==0:
1352 y = table.get(headerUpperVersion[y_name], [])
1353 else:
1354 try:
1355 y1_name = y_name.split('+')[0]
1356 y2_name = y_name.split('+')[1]
1357 y1_value = table.get(y1_name, [])
1358 y2_value = table.get(y2_name, [])
1359 if len(y1_value)==0 or len(y2_value)==0:
1360 y1_value = table.get(headerUpperVersion[y1_name], [])
1361 y2_value = table.get(headerUpperVersion[y2_name], [])
1362 except Exception as e:
1363 msg.warning('exception caught: {0}'.format(e))
1364 x = []
1365 y = []
1366 else:
1367 # create new list with added values (1,2,3) + (4,5,6) = (5,7,9)
1368 y = [x0 + y0 for x0, y0 in zip(y1_value, y2_value)]
1369
1370 return x, y
1371

◆ fit()

python.trfUtils.analytic.fit ( self,
x,
y,
model = 'linear' )

Fitting function For a linear model: y(x) = slope * x + intersect.

Parameters
xlist of input data (list of floats or ints).
ylist of input data (list of floats or ints).
modelmodel name (string).

Definition at line 1275 of file trfUtils.py.

1275 def fit(self, x, y, model='linear'):
1276 try:
1277 self._fit = Fit(x=x, y=y, model=model)
1278 except Exception as e:
1279 msg.warning('fit failed! {0}'.format(e))
1280
1281 return self._fit
1282

◆ formatBytes()

python.trfUtils.analytic.formatBytes ( self,
size )

Definition at line 1374 of file trfUtils.py.

1374 def formatBytes(self, size):
1375 # decimal system
1376 power = 1000
1377 n = 1
1378 power_labels = {1: 'K', 2: 'M', 3: 'G', 4: 'T'}
1379 while size > power:
1380 size /= power
1381 n += 1
1382 return round(size, 2), power_labels[n]+'B/s'
1383
1384

◆ getFittedData()

python.trfUtils.analytic.getFittedData ( self,
filename,
x_name = 'Time',
y_name = 'pss',
precision = 2,
tails = False,
minPoints = 5 )

Definition at line 1303 of file trfUtils.py.

1303 def getFittedData(self, filename, x_name='Time', y_name='pss', precision=2, tails=False, minPoints=5):
1304 _memFileToTable = memFileToTable()
1305 fitResult = {}
1306 table = _memFileToTable.getTable(filename, header=None, separator="\t")
1307 if table:
1308 # extract data to be fitted
1309 x, y = self.extractFromTable(table, x_name, y_name)
1310 # remove tails if desired
1311 # this is useful e.g. for memory monitor data where the first and last values
1312 # represent allocation and de-allocation, ie not interesting
1313 # here tail is defined to be first and last 20% of data
1314 if not tails:
1315 tail = int(len(x)/5)
1316 msg.info('removing tails from the memory monitor data; 20% from each side')
1317 x = x[tail:]
1318 x = x[:-tail]
1319 y = y[tail:]
1320 y = y[:-tail]
1321
1322 if len(x)==len(y) and len(x) > minPoints:
1323 msg.info('fitting {0} vs {1}'.format(y_name, x_name))
1324 try:
1325 fit = self.fit(x, y)
1326 _slope = self.slope()
1327 except Exception as e:
1328 msg.warning('failed to fit data, x={0}, y={1}: {2}'.format(x, y, e))
1329 else:
1330 if _slope:
1331 slope = round(fit.slope(), precision)
1332 chi2 = round(fit.chi2(), precision)
1333 fitResult = {"slope": slope, "chi2": chi2}
1334 if slope:
1335 HRslope, unit = self.formatBytes(slope)
1336 msg.info('slope of the fitted line: {0} {1} (using {2} data points, chi2={3})'.format(HRslope, unit, len(x), chi2))
1337 else:
1338 msg.warning('wrong length of table data, x={0}, y={1} (must be same and length>={2})'.format(x, y, minPoints))
1339
1340 return fitResult
1341

◆ slope()

python.trfUtils.analytic.slope ( self)

Definition at line 1284 of file trfUtils.py.

1284 def slope(self):
1285 slope = None
1286
1287 if self._fit:
1288 slope = self._fit.slope()
1289 else:
1290 msg.warning('Fit has not been defined')
1291
1292 return slope
1293

Member Data Documentation

◆ _fit

python.trfUtils.analytic._fit = None
staticprotected

Definition at line 1265 of file trfUtils.py.


The documentation for this class was generated from the following file: