From 6cbce57106f23049b6b3321111d8a6381f0e2d7c Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 12 Jan 2021 03:03:20 -0500 Subject: [PATCH 1/3] casadm: don't print `Free` entry for ioclass stats Signed-off-by: Michal Mielewczyk --- casadm/statistics_model.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/casadm/statistics_model.c b/casadm/statistics_model.c index 40a2bfd..8360074 100644 --- a/casadm/statistics_model.c +++ b/casadm/statistics_model.c @@ -231,6 +231,18 @@ static void print_usage_stats(struct ocf_stats_usage *stats, FILE* outfile) stats->dirty.fraction, "%lu", stats->dirty.value); } +static void print_ioclass_usage_stats(struct ocf_stats_usage *stats, FILE* outfile) +{ + print_usage_header(outfile); + + print_val_perc_table_row(outfile, "Occupancy", UNIT_BLOCKS, + stats->occupancy.fraction, "%lu", stats->occupancy.value); + print_val_perc_table_row(outfile, "Clean", UNIT_BLOCKS, + stats->clean.fraction, "%lu", stats->clean.value); + print_val_perc_table_row(outfile, "Dirty", UNIT_BLOCKS, + stats->dirty.fraction, "%lu", stats->dirty.value); +} + static void print_req_stats(const struct ocf_stats_requests *stats, FILE *outfile) { @@ -435,7 +447,7 @@ void print_stats_ioclass(struct kcas_io_class *io_class, print_stats_ioclass_conf(io_class, outfile); if (stats_filters & STATS_FILTER_USAGE) - print_usage_stats(&stats->usage, outfile); + print_ioclass_usage_stats(&stats->usage, outfile); if (stats_filters & STATS_FILTER_REQ) print_req_stats(&stats->req, outfile); From 0e1ba12756416baaf62216ea2e82c7a11c022ea7 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 12 Jan 2021 03:05:47 -0500 Subject: [PATCH 2/3] test api: class for ioclass usage stats Signed-off-by: Michal Mielewczyk --- test/functional/api/cas/statistics.py | 48 +++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/test/functional/api/cas/statistics.py b/test/functional/api/cas/statistics.py index 37f3d26..3b4c1c9 100644 --- a/test/functional/api/cas/statistics.py +++ b/test/functional/api/cas/statistics.py @@ -15,6 +15,7 @@ config_stats_core = [ ] config_stats_ioclass = ["io class id", "io class name", "eviction priority", "selective allocation"] usage_stats = ["occupancy", "free", "clean", "dirty"] +usage_stats_ioclass = ["occupancy", "clean", "dirty"] inactive_usage_stats = ["inactive occupancy", "inactive clean", "inactive dirty"] request_stats = [ "read hits", "read partial misses", "read full misses", "read total", @@ -175,8 +176,8 @@ class IoClassStats: except KeyError: pass try: - self.usage_stats = UsageStats( - *[stats[stat] for stat in usage_stats] + self.usage_stats = IoClassUsageStats( + *[stats[stat] for stat in usage_stats_ioclass] ) except KeyError: pass @@ -419,6 +420,49 @@ class UsageStats: return self +class IoClassUsageStats: + def __init__(self, occupancy, clean, dirty): + self.occupancy = occupancy + self.clean = clean + self.dirty = dirty + + def __str__(self): + return ( + f"Usage stats:\n" + f"Occupancy: {self.occupancy}\n" + f"Clean: {self.clean}\n" + f"Dirty: {self.dirty}\n" + ) + + def __repr__(self): + return str(self) + + def __eq__(self, other): + if not other: + return False + return ( + self.occupancy == other.occupancy + and self.clean == other.clean + and self.dirty == other.dirty + ) + + def __ne__(self, other): + return not self == other + + def __add__(self, other): + return UsageStats( + self.occupancy + other.occupancy, + self.clean + other.clean, + self.dirty + other.dirty + ) + + def __iadd__(self, other): + self.occupancy += other.occupancy + self.clean += other.clean + self.dirty += other.dirty + return self + + class InactiveUsageStats: def __init__(self, inactive_occupancy, inactive_clean, inactive_dirty): self.inactive_occupancy = inactive_occupancy From b4a34fe9c9356e685b517beed693ecc658027eef Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 12 Jan 2021 04:18:58 -0500 Subject: [PATCH 3/3] tests: update ioclass stats tests `Free` is no longer a part of the ioclass usage stats Signed-off-by: Michal Mielewczyk --- .../tests/io_class/test_io_class_occupancy.py | 6 +++--- test/functional/tests/io_class/test_io_class_purge.py | 4 ++-- test/functional/tests/stats/test_ioclass_stats.py | 11 ++++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/functional/tests/io_class/test_io_class_occupancy.py b/test/functional/tests/io_class/test_io_class_occupancy.py index c782b69..6a9341a 100644 --- a/test/functional/tests/io_class/test_io_class_occupancy.py +++ b/test/functional/tests/io_class/test_io_class_occupancy.py @@ -11,7 +11,7 @@ import pytest from .io_class_common import * from api.cas.cache_config import CacheMode, CacheLineSize from api.cas.ioclass_config import IoClass -from api.cas.statistics import UsageStats +from api.cas.statistics import IoClassUsageStats from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan from test_tools import fs_utils from test_tools.disk_utils import Filesystem @@ -337,7 +337,7 @@ def test_ioclass_occupancy_sum_cache(): cache.purge_cache() with TestRun.step("Verify stats before IO"): - usage_stats_sum = UsageStats(Size(0), Size(0), Size(0), Size(0)) + usage_stats_sum = IoClassUsageStats(Size(0), Size(0), Size(0)) for i in io_classes: usage_stats_sum += get_io_class_usage(cache, i.id) usage_stats_sum += get_io_class_usage(cache, default_ioclass_id) @@ -364,7 +364,7 @@ def test_ioclass_occupancy_sum_cache(): ) with TestRun.step("Verify stats after IO"): - usage_stats_sum = UsageStats(Size(0), Size(0), Size(0), Size(0)) + usage_stats_sum = IoClassUsageStats(Size(0), Size(0), Size(0)) for i in io_classes: usage_stats_sum += get_io_class_usage(cache, i.id) usage_stats_sum += get_io_class_usage(cache, default_ioclass_id) diff --git a/test/functional/tests/io_class/test_io_class_purge.py b/test/functional/tests/io_class/test_io_class_purge.py index 029aa3a..5316790 100644 --- a/test/functional/tests/io_class/test_io_class_purge.py +++ b/test/functional/tests/io_class/test_io_class_purge.py @@ -8,7 +8,7 @@ from collections import namedtuple import pytest from api.cas import ioclass_config, casadm -from api.cas.statistics import UsageStats +from api.cas.statistics import IoClassUsageStats from core.test_run import TestRun from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan from test_tools import fs_utils @@ -108,7 +108,7 @@ def get_io_class_usage(cache, io_class_id): def verify_ioclass_usage_stats(cache, ioclasses_ids): cache_size = cache.get_statistics().config_stats.cache_size - usage_stats_sum = UsageStats(Size(0), Size(0), Size(0), Size(0)) + usage_stats_sum = IoClassUsageStats(Size(0), Size(0), Size(0)) for i in ioclasses_ids: usage_stats_sum += get_io_class_usage(cache, i) diff --git a/test/functional/tests/stats/test_ioclass_stats.py b/test/functional/tests/stats/test_ioclass_stats.py index ba38fea..613f3c7 100644 --- a/test/functional/tests/stats/test_ioclass_stats.py +++ b/test/functional/tests/stats/test_ioclass_stats.py @@ -16,7 +16,12 @@ from api.cas.cli_messages import ( get_stats_ioclass_id_out_of_range ) from api.cas.statistics import ( - config_stats_ioclass, usage_stats, request_stats, block_stats_core, block_stats_cache + config_stats_ioclass, + usage_stats, + usage_stats_ioclass, + request_stats, + block_stats_core, + block_stats_cache ) from core.test_run import TestRun from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan @@ -147,7 +152,7 @@ def test_ioclass_stats_sum(random_cls): with TestRun.step("Check if per class cache IO class statistics sum up to cache statistics"): # Name of stats, which should not be compared - not_compare_stats = ["clean", "occupancy"] + not_compare_stats = ["clean", "occupancy", "free"] ioclass_id_list = list(range(min_ioclass_id, max_ioclass_id)) # Append default IO class id ioclass_id_list.append(0) @@ -275,7 +280,7 @@ def get_checked_statistics(stat_filter: StatsFilter, per_core: bool): if stat_filter == StatsFilter.conf: return config_stats_ioclass if stat_filter == StatsFilter.usage: - return usage_stats + return usage_stats_ioclass if stat_filter == StatsFilter.blk: return block_stats_core if per_core else block_stats_cache if stat_filter == StatsFilter.req: