1 /*
2  *     Copyright 2010 NorthScale, Inc.
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16 
17 #include "config.h"
18 
19 #include <stdio.h>
20 
21 #include <algorithm>
22 #include <limits>
23 
24 #include "checkpoint.h"
25 #include "ep.h"
26 #include "histo.h"
27 #include "item.h"
28 #include "stored-value.h"
29 #include "vbucket.h"
30 
display(const char *name, size_t size)31 static void display(const char *name, size_t size) {
32     std::cout << name << "\t" << size << std::endl;
33 }
34 
35 template <typename T>
36 struct histo_for_inner {
operator ()histo_for_inner37     void operator()(const HistogramBin<T> *bin) {
38         std::cout << "   " << bin->start() << " - ";
39         if (bin->end() == std::numeric_limits<T>::max()) {
40             std::cout << "inf";
41         } else {
42             std::cout << bin->end();
43         }
44         std::cout << std::endl;
45     }
46 };
47 
48 template <>
49 struct histo_for_inner<hrtime_t> {
operator ()histo_for_inner50     void operator()(const HistogramBin<hrtime_t> *bin) {
51         const std::string endtext(bin->end()
52                                   == std::numeric_limits<hrtime_t>::max()
53                                   ? "inf"
54                                   : hrtime2text(bin->end()));
55         std::cout << "   " << hrtime2text(bin->start())
56                   << " - " << endtext << std::endl;
57     }
58 };
59 
60 template <typename T>
display(const char *name, const Histogram<T> &histo)61 static void display(const char *name, const Histogram<T> &histo) {
62     std::cout << name << std::endl;
63     std::for_each(histo.begin(), histo.end(), histo_for_inner<T>());
64 }
65 
main(int, char **)66 int main(int, char **) {
67     std::string s;
68 
69     display("GIGANTOR", GIGANTOR);
70     display("Stored Value", sizeof(StoredValue));
71 
72     display("Stored Value Factory", sizeof(StoredValueFactory));
73     display("Blob", sizeof(Blob));
74     display("value_t", sizeof(value_t));
75     display("HashTable", sizeof(HashTable));
76     display("Item", sizeof(Item));
77     display("VBucket", sizeof(VBucket));
78     display("VBucketMap", sizeof(VBucketMap));
79     display("Stats", sizeof(EPStats));
80     display("CheckpointManager", sizeof(CheckpointManager));
81     display("Checkpoint\t", sizeof(Checkpoint));
82     display("CheckpointConfig", sizeof(CheckpointConfig));
83     display("Histogram<whatever>", sizeof(Histogram<size_t>));
84     display("HistogramBin<size_t>", sizeof(HistogramBin<size_t>));
85     display("HistogramBin<hrtime_t>", sizeof(HistogramBin<hrtime_t>));
86     display("HistogramBin<int>", sizeof(HistogramBin<int>));
87 
88     std::cout << std::endl << "Histogram Ranges" << std::endl << std::endl;
89 
90     EPStats stats;
91     HashTableDepthStatVisitor dv;
92     display("Default Histo", stats.diskInsertHisto);
93     display("Commit Histo", stats.diskCommitHisto);
94     display("Hash table depth histo", dv.depthHisto);
95     return 0;
96 }
97