summaryrefslogtreecommitdiffstats
path: root/src/kv/KeyValueHistogram.h
blob: 2da44bd4ec2747abd1b7580ccc14e4825d6fc2f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef KeyValueHistogram_H
#define KeyValueHistogram_H

#include <map>
#include <string>
#include "common/Formatter.h"

/**
 *
 * Key Value DB Histogram generator
 *
 */
struct KeyValueHistogram {
  struct value_dist {
    uint64_t count;
    uint32_t max_len;
  };

  struct key_dist {
    uint64_t count;
    uint32_t max_len;
    std::map<int, struct value_dist> val_map; ///< slab id to count, max length of value and key
  };

  std::map<std::string, std::map<int, struct key_dist> > key_hist;
  std::map<int, uint64_t> value_hist;
  int get_key_slab(size_t sz);
  std::string get_key_slab_to_range(int slab);
  int get_value_slab(size_t sz);
  std::string get_value_slab_to_range(int slab);
  void update_hist_entry(std::map<std::string, std::map<int, struct key_dist> >& key_hist,
    const std::string& prefix, size_t key_size, size_t value_size);
  void dump(ceph::Formatter* f);
};

#endif