]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/histogram.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / histogram.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#include "common/histogram.h"
16#include "common/Formatter.h"
17
18// -- pow2_hist_t --
19void pow2_hist_t::dump(Formatter *f) const
20{
21 f->open_array_section("histogram");
22 for (std::vector<int32_t>::const_iterator p = h.begin(); p != h.end(); ++p)
23 f->dump_int("count", *p);
24 f->close_section();
25 f->dump_int("upper_bound", upper_bound());
26}
27
28void pow2_hist_t::encode(bufferlist& bl) const
29{
30 ENCODE_START(1, 1, bl);
11fdf7f2 31 encode(h, bl);
7c673cae
FG
32 ENCODE_FINISH(bl);
33}
34
11fdf7f2 35void pow2_hist_t::decode(bufferlist::const_iterator& p)
7c673cae
FG
36{
37 DECODE_START(1, p);
11fdf7f2 38 decode(h, p);
7c673cae
FG
39 DECODE_FINISH(p);
40}
41
42void pow2_hist_t::generate_test_instances(std::list<pow2_hist_t*>& ls)
43{
44 ls.push_back(new pow2_hist_t);
45 ls.push_back(new pow2_hist_t);
46 ls.back()->h.push_back(1);
47 ls.back()->h.push_back(3);
48 ls.back()->h.push_back(0);
49 ls.back()->h.push_back(2);
50}
51
52void pow2_hist_t::decay(int bits)
53{
54 for (std::vector<int32_t>::iterator p = h.begin(); p != h.end(); ++p) {
55 *p >>= bits;
56 }
57 _contract();
58}