]> git.proxmox.com Git - ceph.git/blame - ceph/src/kv/KeyValueHistogram.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / kv / KeyValueHistogram.cc
CommitLineData
20effc67
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "include/stringify.h"
5#include "KeyValueHistogram.h"
6using std::map;
7using std::string;
8using ceph::Formatter;
9
10#define KEY_SLAB 32
11#define VALUE_SLAB 64
12
13int KeyValueHistogram::get_key_slab(size_t sz)
14{
15 return (sz / KEY_SLAB);
16}
17
18string KeyValueHistogram::get_key_slab_to_range(int slab)
19{
20 int lower_bound = slab * KEY_SLAB;
21 int upper_bound = (slab + 1) * KEY_SLAB;
22 string ret = "[" + stringify(lower_bound) + "," + stringify(upper_bound) + ")";
23 return ret;
24}
25
26int KeyValueHistogram::get_value_slab(size_t sz)
27{
28 return (sz / VALUE_SLAB);
29}
30
31string KeyValueHistogram::get_value_slab_to_range(int slab)
32{
33 int lower_bound = slab * VALUE_SLAB;
34 int upper_bound = (slab + 1) * VALUE_SLAB;
35 string ret = "[" + stringify(lower_bound) + "," + stringify(upper_bound) + ")";
36 return ret;
37}
38
39void KeyValueHistogram::update_hist_entry(map<string, map<int, struct key_dist> >& key_hist,
40 const string& prefix, size_t key_size, size_t value_size)
41{
42 uint32_t key_slab = get_key_slab(key_size);
43 uint32_t value_slab = get_value_slab(value_size);
44 key_hist[prefix][key_slab].count++;
45 key_hist[prefix][key_slab].max_len =
46 std::max<size_t>(key_size, key_hist[prefix][key_slab].max_len);
47 key_hist[prefix][key_slab].val_map[value_slab].count++;
48 key_hist[prefix][key_slab].val_map[value_slab].max_len =
49 std::max<size_t>(value_size,
50 key_hist[prefix][key_slab].val_map[value_slab].max_len);
51}
52
53void KeyValueHistogram::dump(Formatter* f)
54{
55 f->open_object_section("rocksdb_value_distribution");
56 for (auto i : value_hist) {
57 f->dump_unsigned(get_value_slab_to_range(i.first).data(), i.second);
58 }
59 f->close_section();
60
61 f->open_object_section("rocksdb_key_value_histogram");
62 for (auto i : key_hist) {
63 f->dump_string("prefix", i.first);
64 f->open_object_section("key_hist");
65 for (auto k : i.second) {
66 f->dump_unsigned(get_key_slab_to_range(k.first).data(), k.second.count);
67 f->dump_unsigned("max_len", k.second.max_len);
68 f->open_object_section("value_hist");
69 for (auto j : k.second.val_map) {
70 f->dump_unsigned(get_value_slab_to_range(j.first).data(), j.second.count);
71 f->dump_unsigned("max_len", j.second.max_len);
72 }
73 f->close_section();
74 }
75 f->close_section();
76 }
77 f->close_section();
78}