An individual stats entry
| 459 | |
| 460 | |
| 461 | class StatsEntry: |
| 462 | """An individual stats entry""" |
| 463 | |
| 464 | # pylint: disable=unused-argument,no-self-use |
| 465 | |
| 466 | def __init__(self, stattype, statvalue): |
| 467 | self.type = stattype |
| 468 | self.value = statvalue |
| 469 | |
| 470 | if stattype == 1: |
| 471 | self.function = self.scalar |
| 472 | elif stattype == 2: |
| 473 | self.function = self.simple |
| 474 | elif stattype == 3: |
| 475 | self.function = self.combined |
| 476 | elif stattype == 4: |
| 477 | self.function = self.name |
| 478 | elif stattype == 6: |
| 479 | self.function = self.symlink |
| 480 | elif stattype == 7: # STAT_DIR_TYPE_HISTOGRAM_LOG2 |
| 481 | self.function = self.histogram_log2 |
| 482 | elif stattype == 8: # STAT_DIR_TYPE_RING_BUFFER |
| 483 | self.function = self.ring_buffer |
| 484 | elif stattype == 9: # STAT_DIR_TYPE_GAUGE |
| 485 | self.function = self.scalar |
| 486 | else: |
| 487 | self.function = self.illegal |
| 488 | |
| 489 | def illegal(self, stats): |
| 490 | """Invalid or unknown counter type""" |
| 491 | return None |
| 492 | |
| 493 | def scalar(self, stats): |
| 494 | """Scalar counter""" |
| 495 | return self.value |
| 496 | |
| 497 | def simple(self, stats): |
| 498 | """Simple counter""" |
| 499 | counter = StatsSimpleList() |
| 500 | for threads in StatsVector(stats, self.value, "P"): |
| 501 | clist = [v[0] for v in StatsVector(stats, threads[0], "Q")] |
| 502 | counter.append(clist) |
| 503 | return counter |
| 504 | |
| 505 | def combined(self, stats): |
| 506 | """Combined counter""" |
| 507 | counter = StatsCombinedList() |
| 508 | for threads in StatsVector(stats, self.value, "P"): |
| 509 | clist = [StatsTuple(cnt) for cnt in StatsVector(stats, threads[0], "QQ")] |
| 510 | counter.append(clist) |
| 511 | return counter |
| 512 | |
| 513 | def name(self, stats): |
| 514 | """Name counter""" |
| 515 | counter = [] |
| 516 | for name in StatsVector(stats, self.value, "P"): |
| 517 | if name[0]: |
| 518 | counter.append(get_string(stats, name[0])) |