1ba5b814bSMatt Ingenthron/*
2ba5b814bSMatt Ingenthron *     Copyright 2010 NorthScale, Inc.
3ba5b814bSMatt Ingenthron *
4ba5b814bSMatt Ingenthron *   Licensed under the Apache License, Version 2.0 (the "License");
5ba5b814bSMatt Ingenthron *   you may not use this file except in compliance with the License.
6ba5b814bSMatt Ingenthron *   You may obtain a copy of the License at
7ba5b814bSMatt Ingenthron *
8ba5b814bSMatt Ingenthron *       http://www.apache.org/licenses/LICENSE-2.0
9ba5b814bSMatt Ingenthron *
10ba5b814bSMatt Ingenthron *   Unless required by applicable law or agreed to in writing, software
11ba5b814bSMatt Ingenthron *   distributed under the License is distributed on an "AS IS" BASIS,
12ba5b814bSMatt Ingenthron *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ba5b814bSMatt Ingenthron *   See the License for the specific language governing permissions and
14ba5b814bSMatt Ingenthron *   limitations under the License.
15ba5b814bSMatt Ingenthron */
16244c0146SMike Wiederhold
17d067db62STrond Norbye#include "config.h"
18244c0146SMike Wiederhold
19a05fbd4fSDustin Sallings#include <stdio.h>
20244c0146SMike Wiederhold
21ad69d0a9SDustin Sallings#include <algorithm>
22ad69d0a9SDustin Sallings#include <limits>
23a05fbd4fSDustin Sallings
24244c0146SMike Wiederhold#include "checkpoint.h"
25244c0146SMike Wiederhold#include "ep.h"
26244c0146SMike Wiederhold#include "histo.h"
27fc9615cdSMike Wiederhold#include "item.h"
28fc9615cdSMike Wiederhold#include "stored-value.h"
29fc9615cdSMike Wiederhold#include "vbucket.h"
30a05fbd4fSDustin Sallings
31a05fbd4fSDustin Sallingsstatic void display(const char *name, size_t size) {
32a93d5068SDustin Sallings    std::cout << name << "\t" << size << std::endl;
33a05fbd4fSDustin Sallings}
34a05fbd4fSDustin Sallings
3571032eeeSDustin Sallingstemplate <typename T>
36ad69d0a9SDustin Sallingsstruct histo_for_inner {
3771032eeeSDustin Sallings    void operator()(const HistogramBin<T> *bin) {
3871032eeeSDustin Sallings        std::cout << "   " << bin->start() << " - ";
3971032eeeSDustin Sallings        if (bin->end() == std::numeric_limits<T>::max()) {
4071032eeeSDustin Sallings            std::cout << "inf";
4171032eeeSDustin Sallings        } else {
4271032eeeSDustin Sallings            std::cout << bin->end();
4371032eeeSDustin Sallings        }
4471032eeeSDustin Sallings        std::cout << std::endl;
4571032eeeSDustin Sallings    }
4671032eeeSDustin Sallings};
4771032eeeSDustin Sallings
4871032eeeSDustin Sallingstemplate <>
4971032eeeSDustin Sallingsstruct histo_for_inner<hrtime_t> {
50ad69d0a9SDustin Sallings    void operator()(const HistogramBin<hrtime_t> *bin) {
5118770839SSundar Sridharan        const std::string endtext(bin->end()
5218770839SSundar Sridharan                                  == std::numeric_limits<hrtime_t>::max()
53ad69d0a9SDustin Sallings                                  ? "inf"
54ad69d0a9SDustin Sallings                                  : hrtime2text(bin->end()));
55ad69d0a9SDustin Sallings        std::cout << "   " << hrtime2text(bin->start())
56ad69d0a9SDustin Sallings                  << " - " << endtext << std::endl;
57ad69d0a9SDustin Sallings    }
58ad69d0a9SDustin Sallings};
59ad69d0a9SDustin Sallings
6071032eeeSDustin Sallingstemplate <typename T>
6171032eeeSDustin Sallingsstatic void display(const char *name, const Histogram<T> &histo) {
62ad69d0a9SDustin Sallings    std::cout << name << std::endl;
6371032eeeSDustin Sallings    std::for_each(histo.begin(), histo.end(), histo_for_inner<T>());
64ad69d0a9SDustin Sallings}
65ad69d0a9SDustin Sallings
66e83145c8SDustin Sallingsint main(int, char **) {
67d6f38a67STrond Norbye    std::string s;
686c190ce0SDustin Sallings
69a93d5068SDustin Sallings    display("GIGANTOR", GIGANTOR);
70b04c2847SMike Wiederhold    display("Stored Value", sizeof(StoredValue));
716c190ce0SDustin Sallings
725deb3f8fSDustin Sallings    display("Stored Value Factory", sizeof(StoredValueFactory));
73897e542eSDustin Sallings    display("Blob", sizeof(Blob));
746c190ce0SDustin Sallings    display("value_t", sizeof(value_t));
75a05fbd4fSDustin Sallings    display("HashTable", sizeof(HashTable));
76a05fbd4fSDustin Sallings    display("Item", sizeof(Item));
77a05fbd4fSDustin Sallings    display("VBucket", sizeof(VBucket));
78a05fbd4fSDustin Sallings    display("VBucketMap", sizeof(VBucketMap));
797bf5fee9SDustin Sallings    display("Stats", sizeof(EPStats));
804f4e23a4SDustin Sallings    display("CheckpointManager", sizeof(CheckpointManager));
814f4e23a4SDustin Sallings    display("Checkpoint\t", sizeof(Checkpoint));
824f4e23a4SDustin Sallings    display("CheckpointConfig", sizeof(CheckpointConfig));
83b002a889SDustin Sallings    display("Histogram<whatever>", sizeof(Histogram<size_t>));
84b002a889SDustin Sallings    display("HistogramBin<size_t>", sizeof(HistogramBin<size_t>));
85b002a889SDustin Sallings    display("HistogramBin<hrtime_t>", sizeof(HistogramBin<hrtime_t>));
86b002a889SDustin Sallings    display("HistogramBin<int>", sizeof(HistogramBin<int>));
87ad69d0a9SDustin Sallings
88ad69d0a9SDustin Sallings    std::cout << std::endl << "Histogram Ranges" << std::endl << std::endl;
89ad69d0a9SDustin Sallings
90ad69d0a9SDustin Sallings    EPStats stats;
9171032eeeSDustin Sallings    HashTableDepthStatVisitor dv;
92ad69d0a9SDustin Sallings    display("Default Histo", stats.diskInsertHisto);
93d596c36aSDustin Sallings    display("Commit Histo", stats.diskCommitHisto);
9471032eeeSDustin Sallings    display("Hash table depth histo", dv.depthHisto);
95a05fbd4fSDustin Sallings    return 0;
96a05fbd4fSDustin Sallings}
97