LCOV - code coverage report
Current view: top level - module/bdev/ocf - stats.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 57 0.0 %
Date: 2024-11-05 10:06:02 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2018 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  */
       5             : 
       6             : #include "ctx.h"
       7             : #include "stats.h"
       8             : 
       9             : int
      10           0 : vbdev_ocf_stats_get(ocf_cache_t cache, char *core_name, struct vbdev_ocf_stats *stats)
      11             : {
      12             :         int status;
      13           0 :         ocf_core_t core;
      14             : 
      15           0 :         status = ocf_core_get_by_name(cache, core_name, strlen(core_name), &core);
      16           0 :         if (status) {
      17           0 :                 return status;
      18             :         }
      19             : 
      20           0 :         return ocf_stats_collect_core(core, &stats->usage, &stats->reqs, &stats->blocks, &stats->errors);
      21             : }
      22             : 
      23             : int
      24           0 : vbdev_ocf_stats_reset(ocf_cache_t cache, char *core_name)
      25             : {
      26             :         int status;
      27           0 :         ocf_core_t core;
      28             : 
      29           0 :         status = ocf_core_get_by_name(cache, core_name, strlen(core_name), &core);
      30           0 :         if (status) {
      31           0 :                 return status;
      32             :         }
      33             : 
      34           0 :         ocf_core_stats_initialize(core);
      35             : 
      36           0 :         return 0;
      37             : }
      38             : 
      39             : #define WJSON_STAT(w, stats, group, field, units) \
      40             :         spdk_json_write_named_object_begin(w, #field); \
      41             :         spdk_json_write_named_uint64(w, "count", stats->group.field.value); \
      42             :         spdk_json_write_named_string_fmt(w, "percentage", "%lu.%lu", \
      43             :                 stats->group.field.fraction / 100, stats->group.field.fraction % 100); \
      44             :         spdk_json_write_named_string(w, "units", units); \
      45             :         spdk_json_write_object_end(w);
      46             : 
      47             : void
      48           0 : vbdev_ocf_stats_write_json(struct spdk_json_write_ctx *w, struct vbdev_ocf_stats *stats)
      49             : {
      50           0 :         spdk_json_write_object_begin(w);
      51             : 
      52           0 :         spdk_json_write_named_object_begin(w, "usage");
      53           0 :         WJSON_STAT(w, stats, usage, occupancy, "4KiB blocks");
      54           0 :         WJSON_STAT(w, stats, usage, free, "4KiB blocks");
      55           0 :         WJSON_STAT(w, stats, usage, clean, "4KiB blocks");
      56           0 :         WJSON_STAT(w, stats, usage, dirty, "4KiB blocks");
      57           0 :         spdk_json_write_object_end(w);
      58             : 
      59           0 :         spdk_json_write_named_object_begin(w, "requests");
      60           0 :         WJSON_STAT(w, stats, reqs, rd_hits, "Requests");
      61           0 :         WJSON_STAT(w, stats, reqs, rd_partial_misses, "Requests");
      62           0 :         WJSON_STAT(w, stats, reqs, rd_full_misses, "Requests");
      63           0 :         WJSON_STAT(w, stats, reqs, rd_total, "Requests");
      64           0 :         WJSON_STAT(w, stats, reqs, wr_hits, "Requests");
      65           0 :         WJSON_STAT(w, stats, reqs, wr_partial_misses, "Requests");
      66           0 :         WJSON_STAT(w, stats, reqs, wr_full_misses, "Requests");
      67           0 :         WJSON_STAT(w, stats, reqs, wr_total, "Requests");
      68           0 :         WJSON_STAT(w, stats, reqs, rd_pt, "Requests");
      69           0 :         WJSON_STAT(w, stats, reqs, wr_pt, "Requests");
      70           0 :         WJSON_STAT(w, stats, reqs, serviced, "Requests");
      71           0 :         WJSON_STAT(w, stats, reqs, total, "Requests");
      72           0 :         spdk_json_write_object_end(w);
      73             : 
      74           0 :         spdk_json_write_named_object_begin(w, "blocks");
      75           0 :         WJSON_STAT(w, stats, blocks, core_volume_rd, "4KiB blocks");
      76           0 :         WJSON_STAT(w, stats, blocks, core_volume_wr, "4KiB blocks");
      77           0 :         WJSON_STAT(w, stats, blocks, core_volume_total, "4KiB blocks");
      78           0 :         WJSON_STAT(w, stats, blocks, cache_volume_rd, "4KiB blocks");
      79           0 :         WJSON_STAT(w, stats, blocks, cache_volume_wr, "4KiB blocks");
      80           0 :         WJSON_STAT(w, stats, blocks, cache_volume_total, "4KiB blocks");
      81           0 :         WJSON_STAT(w, stats, blocks, volume_rd, "4KiB blocks");
      82           0 :         WJSON_STAT(w, stats, blocks, volume_wr, "4KiB blocks");
      83           0 :         WJSON_STAT(w, stats, blocks, volume_total, "4KiB blocks");
      84           0 :         spdk_json_write_object_end(w);
      85             : 
      86           0 :         spdk_json_write_named_object_begin(w, "errors");
      87           0 :         WJSON_STAT(w, stats, errors, core_volume_rd, "Requests");
      88           0 :         WJSON_STAT(w, stats, errors, core_volume_wr, "Requests");
      89           0 :         WJSON_STAT(w, stats, errors, core_volume_total, "Requests");
      90           0 :         WJSON_STAT(w, stats, errors, cache_volume_rd, "Requests");
      91           0 :         WJSON_STAT(w, stats, errors, cache_volume_wr, "Requests");
      92           0 :         WJSON_STAT(w, stats, errors, cache_volume_total, "Requests");
      93           0 :         WJSON_STAT(w, stats, errors, total, "Requests");
      94           0 :         spdk_json_write_object_end(w);
      95             : 
      96           0 :         spdk_json_write_object_end(w);
      97           0 : }

Generated by: LCOV version 1.15