Skip to content

Commit

Permalink
test-api: add methods to statistics
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Gierszewski <kamil.gierszewski@huawei.com>
  • Loading branch information
Kamil Gierszewski committed Dec 13, 2024
1 parent 24b88f1 commit bb24b32
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions test/functional/api/cas/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def __eq__(self, other):
getattr(other, stats_item) for stats_item in other.__dict__
]

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.usage_stats -= other.usage_stats
self.request_stats -= other.request_stats
self.block_stats -= other.block_stats
self.error_stats -= other.error_stats
return self


class CoreStats:
def __init__(
Expand All @@ -93,6 +103,13 @@ def __init__(
case StatsFilter.err:
self.error_stats = ErrorStats(stats_dict, percentage_val)

def __sub__(self, other):
self.usage_stats -= other.usage_stats
self.request_stats -= other.request_stats
self.block_stats -= other.block_stats
self.error_stats -= other.error_stats
return self

def __str__(self):
# stats_list contains all Class.__str__ methods initialized in CacheStats
stats_list = [str(getattr(self, stats_item)) for stats_item in self.__dict__]
Expand All @@ -104,6 +121,9 @@ def __eq__(self, other):
getattr(other, stats_item) for stats_item in other.__dict__
]

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])


class CoreIoClassStats:
def __init__(
Expand Down Expand Up @@ -140,6 +160,14 @@ def __str__(self):
stats_list = [str(getattr(self, stats_item)) for stats_item in self.__dict__]
return "\n".join(stats_list)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.usage_stats -= other.usage_stats
self.request_stats -= other.request_stats
self.block_stats -= other.block_stats


class CacheIoClassStats(CoreIoClassStats):
def __init__(
Expand Down Expand Up @@ -220,6 +248,9 @@ def __eq__(self, other):
and self.status == other.status
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])


class CoreConfigStats:
def __init__(self, stats_dict):
Expand Down Expand Up @@ -263,6 +294,9 @@ def __eq__(self, other):
and self.seq_cutoff_policy == other.seq_cutoff_policy
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])


class IoClassConfigStats:
def __init__(self, stats_dict):
Expand Down Expand Up @@ -290,6 +324,9 @@ def __eq__(self, other):
and self.max_size == other.max_size
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])


class UsageStats:
def __init__(self, stats_dict, percentage_val):
Expand Down Expand Up @@ -336,6 +373,16 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.occupancy -= other.occupancy
self.free -= other.free
self.clean -= other.clean
self.dirty -= other.dirty
return self


class IoClassUsageStats:
def __init__(self, stats_dict, percentage_val):
Expand Down Expand Up @@ -367,6 +414,15 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.occupancy -= other.occupancy
self.clean -= other.clean
self.dirty -= other.dirty
return self


class RequestStats:
def __init__(self, stats_dict, percentage_val):
Expand Down Expand Up @@ -413,6 +469,18 @@ def __eq__(self, other):
and self.requests_total == other.requests_total
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.read -= other.read
self.write -= other.write
self.pass_through_reads -= other.pass_through_reads
self.pass_through_writes -= other.pass_through_writes
self.requests_serviced -= other.requests_serviced
self.requests_total -= other.requests_total
return self


class RequestStatsChunk:
def __init__(self, stats_dict, percentage_val: bool, operation: OperationType):
Expand Down Expand Up @@ -444,6 +512,16 @@ def __eq__(self, other):
and self.total == other.total
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.hits -= other.hits
self.part_misses -= other.part_misses
self.full_misses -= other.full_misses
self.total -= other.total
return self


class BlockStats:
def __init__(self, stats_dict, percentage_val):
Expand Down Expand Up @@ -474,6 +552,15 @@ def __eq__(self, other):
self.core == other.core and self.cache == other.cache and self.exp_obj == other.exp_obj
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.core -= other.core
self.cache -= other.cache
self.exp_obj -= other.exp_obj
return self


class ErrorStats:
def __init__(self, stats_dict, percentage_val):
Expand Down Expand Up @@ -503,6 +590,15 @@ def __eq__(self, other):
and self.total_errors == other.total_errors
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.cache -= other.cache
self.core -= other.core
self.total_errors -= other.total_errors
return self


class BasicStatsChunk:
def __init__(self, stats_dict: dict, percentage_val: bool, device: str):
Expand All @@ -521,6 +617,15 @@ def __eq__(self, other):
self.reads == other.reads and self.writes == other.writes and self.total == other.total
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.reads -= other.reads
self.writes -= other.writes
self.total -= other.total
return self


class BasicStatsChunkError:
def __init__(self, stats_dict: dict, percentage_val: bool, device: str):
Expand All @@ -539,6 +644,15 @@ def __eq__(self, other):
self.reads == other.reads and self.writes == other.writes and self.total == other.total
)

def __iter__(self):
return iter([getattr(self, stats_item) for stats_item in self.__dict__])

def __sub__(self, other):
self.reads -= other.reads
self.writes -= other.writes
self.total -= other.total
return self


def get_stat_value(stat_dict: dict, key: str):
idx = key.index("[")
Expand Down

0 comments on commit bb24b32

Please sign in to comment.