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 */
16a05fbd4fSDustin Sallings#include <stdio.h>
17244c0146SMike Wiederhold
18ad69d0a9SDustin Sallings#include <algorithm>
19ad69d0a9SDustin Sallings#include <limits>
20a05fbd4fSDustin Sallings
21bdbc6979SDave Rigby#include "atomic_unordered_map.h"
22244c0146SMike Wiederhold#include "checkpoint.h"
23897bc920SDave Rigby#include "checkpoint_config.h"
24032ef570STim Bradgate#include "checkpoint_manager.h"
25e7754280SDave Rigby#include "common.h"
26b29564e2SDave Rigby#include "couch-kvstore/couch-kvstore.h"
2750b7fa7cSJim Walker#include "dcp/response.h"
28bdbc6979SDave Rigby#include "dcp/stream.h"
2933033905SDave Rigby#include "hash_table_stat_visitor.h"
30fc9615cdSMike Wiederhold#include "item.h"
31b29564e2SDave Rigby#include "kvstore_priv.h"
325ecba1e7SDave Rigby#include "persistence_callback.h"
33f0fdb2edSDaniel Owen#include "probabilistic_counter.h"
34e20fec5dSDave Rigby#include "stats.h"
35fc9615cdSMike Wiederhold#include "stored-value.h"
36fc9615cdSMike Wiederhold#include "vbucket.h"
3786c5b3c6STim Bradgate#include "vbucketmap.h"
3850b7fa7cSJim Walker#include <platform/histogram.h>
3950b7fa7cSJim Walker#include <platform/timeutils.h>
40a05fbd4fSDustin Sallings
41a05fbd4fSDustin Sallingsstatic void display(const char *name, size_t size) {
42a93d5068SDustin Sallings    std::cout << name << "\t" << size << std::endl;
43a05fbd4fSDustin Sallings}
44a05fbd4fSDustin Sallings
458b25bbfdSEugen-Alexandru Virtantemplate <typename T, template <class> class Traits>
46ad69d0a9SDustin Sallingsstruct histo_for_inner {
478b25bbfdSEugen-Alexandru Virtan    void operator()(const std::unique_ptr<HistogramBin<T, Traits>>& bin) {
4871032eeeSDustin Sallings        std::cout << "   " << bin->start() << " - ";
498b25bbfdSEugen-Alexandru Virtan        if (bin->end() == Traits<T>::max()) {
5071032eeeSDustin Sallings            std::cout << "inf";
5171032eeeSDustin Sallings        } else {
5271032eeeSDustin Sallings            std::cout << bin->end();
5371032eeeSDustin Sallings        }
5471032eeeSDustin Sallings        std::cout << std::endl;
5571032eeeSDustin Sallings    }
5671032eeeSDustin Sallings};
5771032eeeSDustin Sallings
588b25bbfdSEugen-Alexandru Virtantemplate <typename T, template <class> class Traits>
598b25bbfdSEugen-Alexandru Virtanstatic void display(const char* name, const Histogram<T, Traits>& histo) {
60ad69d0a9SDustin Sallings    std::cout << name << std::endl;
618b25bbfdSEugen-Alexandru Virtan    std::for_each(histo.begin(), histo.end(), histo_for_inner<T, Traits>());
62ad69d0a9SDustin Sallings}
63ad69d0a9SDustin Sallings
64e83145c8SDustin Sallingsint main(int, char **) {
65d6f38a67STrond Norbye    std::string s;
666c190ce0SDustin Sallings
67a93d5068SDustin Sallings    display("GIGANTOR", GIGANTOR);
6841693f57SDave Rigby    display("StoredValue", sizeof(StoredValue));
6941693f57SDave Rigby    display("StoredValue with 15 byte key",
70cd62790fSJim Walker            StoredValue::getRequiredStorage(
71cd62790fSJim Walker                    DocKey("1234567890abcde", DocKeyEncodesCollectionId::No)));
7253f59cd4SSriram Ganesan    display("Ordered Stored Value", sizeof(OrderedStoredValue));
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));
83b7836b72SRichard de Mellow    display("Histogram<whatever>", Histogram<size_t>().getMemFootPrint());
84b002a889SDustin Sallings    display("HistogramBin<size_t>", sizeof(HistogramBin<size_t>));
85b002a889SDustin Sallings    display("HistogramBin<int>", sizeof(HistogramBin<int>));
868b25bbfdSEugen-Alexandru Virtan    display("HistogramBin<microseconds>",
878b25bbfdSEugen-Alexandru Virtan            sizeof(MicrosecondHistogram::bin_type));
88b7836b72SRichard de Mellow    display("MicrosecondHistogram", MicrosecondHistogram().getMemFootPrint());
893864c2b3SRichard de Mellow    EPStats stats;
900f1a35e9SRichard de Mellow    const size_t size = GlobalTask::allTaskIds.size();
910f1a35e9SRichard de Mellow    stats.schedulingHisto.resize(size);
920f1a35e9SRichard de Mellow    stats.taskRuntimeHisto.resize(size);
930f1a35e9SRichard de Mellow    display("EPStats", stats.getMemFootPrint());
940f1a35e9SRichard de Mellow    display("FileStats", FileStats().getMemFootPrint());
950f1a35e9SRichard de Mellow    display("KVStoreStats", KVStoreStats().getMemFootPrint());
960f1a35e9SRichard de Mellow    display("Histogram<size_t>{ExponentialGenerator<size_t>(1, 2), 50}",
970f1a35e9SRichard de Mellow            Histogram<size_t>{ExponentialGenerator<size_t>(1, 2), 50}
980f1a35e9SRichard de Mellow                    .getMemFootPrint());
993864c2b3SRichard de Mellow    display("HdrHistogram frequency histo",
1003864c2b3SRichard de Mellow            stats.activeOrPendingFrequencyValuesEvictedHisto.getMemFootPrint());
1010f1a35e9SRichard de Mellow    display("Hdr1sfMicroSecHistogram",
1020f1a35e9SRichard de Mellow            Hdr1sfMicroSecHistogram().getMemFootPrint());
1030f1a35e9SRichard de Mellow    display("Hdr2sfMicroSecHistogram",
1040f1a35e9SRichard de Mellow            Hdr2sfMicroSecHistogram().getMemFootPrint());
1050f1a35e9SRichard de Mellow
1060f1a35e9SRichard de Mellow    display("HdrUint8Histogram", HdrUint8Histogram().getMemFootPrint());
1070f1a35e9SRichard de Mellow    display("Hdr1sfInt32Histogram", Hdr1sfInt32Histogram().getMemFootPrint());
1080f1a35e9SRichard de Mellow
1090f1a35e9SRichard de Mellow    display("HdrHistogram(0, std::numeric_limits<int32_t>::max(), 2)",
1100f1a35e9SRichard de Mellow            HdrHistogram(0, std::numeric_limits<int32_t>::max() - 1, 2)
1110f1a35e9SRichard de Mellow                    .getMemFootPrint());
1120f1a35e9SRichard de Mellow    display("HdrHistogram(0, std::numeric_limits<int32_t>::max(), 1)",
1130f1a35e9SRichard de Mellow            HdrHistogram(0, std::numeric_limits<int32_t>::max() - 1, 1)
1140f1a35e9SRichard de Mellow                    .getMemFootPrint());
1150f1a35e9SRichard de Mellow    display("HdrHistogram(0, std::numeric_limits<int64_t>::max(), 2)",
1160f1a35e9SRichard de Mellow            HdrHistogram(0, std::numeric_limits<int64_t>::max() - 1, 2)
1170f1a35e9SRichard de Mellow                    .getMemFootPrint());
1180f1a35e9SRichard de Mellow    display("HdrHistogram(0, std::numeric_limits<int64_t>::max(), 1)",
1190f1a35e9SRichard de Mellow            HdrHistogram(0, std::numeric_limits<int64_t>::max() - 1, 1)
1200f1a35e9SRichard de Mellow                    .getMemFootPrint());
1210f1a35e9SRichard de Mellow
122b29564e2SDave Rigby    display("IORequest", sizeof(IORequest));
123b29564e2SDave Rigby    display("CouchRequest", sizeof(CouchRequest));
1245ecba1e7SDave Rigby    display("PersistenceCallback", sizeof(PersistenceCallback));
125d91c6368SDave Rigby    display("AtomicUnorderedMap<uint32_t, SingleThreadedRCPtr<Stream>>",
126d91c6368SDave Rigby            sizeof(AtomicUnorderedMap<uint32_t, SingleThreadedRCPtr<Stream>>));
127f0fdb2edSDaniel Owen    display("ProbabilisticCounter<uint8_t>",
128f0fdb2edSDaniel Owen            sizeof(ProbabilisticCounter<uint8_t>));
12950b7fa7cSJim Walker    display("DcpResponse", sizeof(DcpResponse));
13050b7fa7cSJim Walker    display("MutationResponse", sizeof(MutationResponse));
13150b7fa7cSJim Walker    display("queued_item", sizeof(queued_item));
132ad69d0a9SDustin Sallings
133ad69d0a9SDustin Sallings    std::cout << std::endl << "Histogram Ranges" << std::endl << std::endl;
134ad69d0a9SDustin Sallings
13571032eeeSDustin Sallings    HashTableDepthStatVisitor dv;
1363864c2b3SRichard de Mellow    display("Default Histo", stats.diskInsertHisto.getMemFootPrint());
1373864c2b3SRichard de Mellow    display("Commit Histo", stats.diskCommitHisto.getMemFootPrint());
1383864c2b3SRichard de Mellow    display("Hash table depth histo", dv.depthHisto.getMemFootPrint());
139a05fbd4fSDustin Sallings    return 0;
140a05fbd4fSDustin Sallings}
141