1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2016 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #include <iostream>
19 
20 #include <phosphor/phosphor.h>
21 
22 /** \file
23  * This program generates some interesting statistics about Phosphor's internal
24  * representations, e.g. object sizes etc.
25  */
26 
27 phosphor::tracepoint_info tpi = {
28     "category",
29     "name",
30     phosphor::TraceEvent::Type::Instant,
31     {{"arg1", "arg2"}},
32     {{phosphor::TraceArgument::Type::is_none, phosphor::TraceArgument::Type::is_none}}
33 };
34 
main(int argc, char** argv)35 int main(int argc, char** argv) {
36 
37     using namespace phosphor;
38 
39     std::cout << "\nStructure Sizes\n";
40     std::cout << "===================\n";
41 
42     std::cout << "ChunkLock: " << sizeof(ChunkLock) << " bytes\n";
43     std::cout << "TraceArgument: " << sizeof(TraceArgument) << " bytes\n";
44     std::cout << "TraceEvent: " << sizeof(TraceEvent) << " bytes\n";
45     std::cout << "TraceChunk: " << sizeof(TraceChunk) << " bytes\n";
46     std::cout << "CategoryRegistry: " << sizeof(CategoryRegistry) << " bytes\n";
47     std::cout << "TraceLog: " << sizeof(TraceLog) << " bytes\n";
48 
49     TraceLog log;
50     log.start(TraceConfig(BufferMode::fixed, 100 * 1024 * 1024));
51     while(log.isEnabled()) {
52         log.logEvent(&tpi, NoneType(), NoneType());
53     }
54     auto buffer = log.getBuffer();
55 
56     std::cout << "\nCapacities\n";
57     std::cout << "===================\n";
58     std::cout << "TraceChunk: " << TraceChunk::chunk_size << " trace events\n";
59     std::cout << "100MiB TraceBuffer: " << buffer->chunk_count() << " trace chunks\n";
60 
61     int n = 0;
62     for(const auto& event : *buffer) {
63         n++;
64     }
65     std::cout << "100MiB TraceBuffer: " << n << " trace events\n";
66 
67 }
68