diff mbox series

[2/3] block/accounting: introduce block size histogram

Message ID 1561020872-6214-3-git-send-email-pizhenwei@bytedance.com (mailing list archive)
State New, archived
Headers show
Series Add block size histogram qapi interface | expand

Commit Message

zhenwei pi June 20, 2019, 8:54 a.m. UTC
Introduce block size histogram statics for block devices.

For read/write/flush operation type, the block size region
[0, +inf) is divided into subregions by several points.
It works like block latency histogram.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 block/accounting.c         | 24 ++++++++++++++++++++++++
 include/block/accounting.h |  4 ++++
 2 files changed, 28 insertions(+)

Comments

Vladimir Sementsov-Ogievskiy June 21, 2019, 9:48 a.m. UTC | #1
20.06.2019 11:54, zhenwei pi wrote:
> Introduce block size histogram statics for block devices.
> 
> For read/write/flush operation type, the block size region
> [0, +inf) is divided into subregions by several points.
> It works like block latency histogram.
> 
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>   block/accounting.c         | 24 ++++++++++++++++++++++++
>   include/block/accounting.h |  4 ++++
>   2 files changed, 28 insertions(+)
> 
> diff --git a/block/accounting.c b/block/accounting.c
> index bb8148b6b1..94d5aa292e 100644
> --- a/block/accounting.c
> +++ b/block/accounting.c
> @@ -187,6 +187,27 @@ void block_latency_histograms_clear(BlockAcctStats *stats)
>       }
>   }
>   
> +int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
> +                                uint64List *boundaries)
> +{
> +    BlockHistogram *hist = &stats->size_histogram[type];
> +
> +    return block_histogram_set(hist, boundaries);
> +}
> +
> +void block_size_histograms_clear(BlockAcctStats *stats)
> +{
> +    int i;
> +
> +    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
> +        BlockHistogram *hist = &stats->size_histogram[i];
> +        g_free(hist->bins);
> +        g_free(hist->boundaries);
> +        memset(hist, 0, sizeof(*hist));

And this is the duplication I've told about in 01

> +    }
> +}
> +
> +
>   static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
>                                    bool failed)
>   {
> @@ -211,6 +232,9 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
>   
>       block_histogram_account(&stats->latency_histogram[cookie->type],
>                                       latency_ns);
> +    block_histogram_account(&stats->size_histogram[cookie->type],
> +                                    cookie->bytes);
> +
>   
>       if (!failed || stats->account_failed) {
>           stats->total_time_ns[cookie->type] += latency_ns;
> diff --git a/include/block/accounting.h b/include/block/accounting.h
> index 270fddb69c..49d3a78f48 100644
> --- a/include/block/accounting.h
> +++ b/include/block/accounting.h
> @@ -89,6 +89,7 @@ struct BlockAcctStats {
>       bool account_invalid;
>       bool account_failed;
>       BlockHistogram latency_histogram[BLOCK_MAX_IOTYPE];
> +    BlockHistogram size_histogram[BLOCK_MAX_IOTYPE];
>   };
>   
>   typedef struct BlockAcctCookie {
> @@ -117,5 +118,8 @@ double block_acct_queue_depth(BlockAcctTimedStats *stats,
>   int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
>                                   uint64List *boundaries);
>   void block_latency_histograms_clear(BlockAcctStats *stats);
> +int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
> +                                uint64List *boundaries);

Hmm, uncommon indentation you use. In Qemu the second line of parameters should start
at the position of first symbol after '(', like this:

int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
                              uint64List *boundaries);

> +void block_size_histograms_clear(BlockAcctStats *stats);
>   
>   #endif
>
diff mbox series

Patch

diff --git a/block/accounting.c b/block/accounting.c
index bb8148b6b1..94d5aa292e 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -187,6 +187,27 @@  void block_latency_histograms_clear(BlockAcctStats *stats)
     }
 }
 
+int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
+                                uint64List *boundaries)
+{
+    BlockHistogram *hist = &stats->size_histogram[type];
+
+    return block_histogram_set(hist, boundaries);
+}
+
+void block_size_histograms_clear(BlockAcctStats *stats)
+{
+    int i;
+
+    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
+        BlockHistogram *hist = &stats->size_histogram[i];
+        g_free(hist->bins);
+        g_free(hist->boundaries);
+        memset(hist, 0, sizeof(*hist));
+    }
+}
+
+
 static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
                                  bool failed)
 {
@@ -211,6 +232,9 @@  static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
 
     block_histogram_account(&stats->latency_histogram[cookie->type],
                                     latency_ns);
+    block_histogram_account(&stats->size_histogram[cookie->type],
+                                    cookie->bytes);
+
 
     if (!failed || stats->account_failed) {
         stats->total_time_ns[cookie->type] += latency_ns;
diff --git a/include/block/accounting.h b/include/block/accounting.h
index 270fddb69c..49d3a78f48 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -89,6 +89,7 @@  struct BlockAcctStats {
     bool account_invalid;
     bool account_failed;
     BlockHistogram latency_histogram[BLOCK_MAX_IOTYPE];
+    BlockHistogram size_histogram[BLOCK_MAX_IOTYPE];
 };
 
 typedef struct BlockAcctCookie {
@@ -117,5 +118,8 @@  double block_acct_queue_depth(BlockAcctTimedStats *stats,
 int block_latency_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
                                 uint64List *boundaries);
 void block_latency_histograms_clear(BlockAcctStats *stats);
+int block_size_histogram_set(BlockAcctStats *stats, enum BlockAcctType type,
+                                uint64List *boundaries);
+void block_size_histograms_clear(BlockAcctStats *stats);
 
 #endif