]>
Commit | Line | Data |
---|---|---|
9b74279f | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
9b74279f | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
9b74279f FC |
7 | */ |
8 | ||
9 | #include "squid.h" | |
7e10ac87 | 10 | #include "base/PackableStream.h" |
9b74279f FC |
11 | #include "ipc/Messages.h" |
12 | #include "ipc/TypedMsgHdr.h" | |
13 | #include "mgr/Registration.h" | |
f079ed87 | 14 | #include "sbuf/Stats.h" |
9b74279f | 15 | #include "SBufStatsAction.h" |
9b74279f | 16 | |
f079ed87 AR |
17 | /// creates a new size-at-destruct-time histogram |
18 | static StatHist * | |
19 | makeDestructTimeHist() { | |
20 | const auto stats = new StatHist; | |
21 | stats->logInit(100, 30.0, 128000.0); | |
22 | return stats; | |
23 | } | |
24 | ||
25 | /// the SBuf size-at-destruct-time histogram | |
26 | static StatHist & | |
27 | collectSBufDestructTimeStats() | |
28 | { | |
29 | static auto stats = makeDestructTimeHist(); | |
30 | return *stats; | |
31 | } | |
32 | ||
33 | /// the MemBlob size-at-destruct-time histogram | |
34 | static StatHist & | |
35 | collectMemBlobDestructTimeStats() | |
36 | { | |
37 | static auto stats = makeDestructTimeHist(); | |
38 | return *stats; | |
39 | } | |
40 | ||
41 | /// record the size an SBuf had when it was destructed | |
42 | static void | |
43 | recordSBufSizeAtDestruct(const size_t sz) | |
44 | { | |
45 | collectSBufDestructTimeStats().count(static_cast<double>(sz)); | |
46 | } | |
47 | ||
48 | /// record the size a MemBlob had when it was destructed | |
49 | static void | |
50 | recordMemBlobSizeAtDestruct(const size_t sz) | |
51 | { | |
52 | collectMemBlobDestructTimeStats().count(static_cast<double>(sz)); | |
53 | } | |
54 | ||
9b74279f | 55 | SBufStatsAction::SBufStatsAction(const Mgr::CommandPointer &cmd_): |
f53969cc | 56 | Action(cmd_) |
9b74279f FC |
57 | { } //default constructor is OK for data member |
58 | ||
59 | SBufStatsAction::Pointer | |
60 | SBufStatsAction::Create(const Mgr::CommandPointer &cmd) | |
61 | { | |
62 | return new SBufStatsAction(cmd); | |
63 | } | |
64 | ||
65 | void | |
66 | SBufStatsAction::add(const Mgr::Action& action) | |
67 | { | |
68 | sbdata += dynamic_cast<const SBufStatsAction&>(action).sbdata; | |
69 | mbdata += dynamic_cast<const SBufStatsAction&>(action).mbdata; | |
ff1eb053 FC |
70 | sbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).sbsizesatdestruct; |
71 | mbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).mbsizesatdestruct; | |
9b74279f FC |
72 | } |
73 | ||
74 | void | |
75 | SBufStatsAction::collect() | |
76 | { | |
77 | sbdata = SBuf::GetStats(); | |
78 | mbdata = MemBlob::GetStats(); | |
b3c7741c AR |
79 | sbsizesatdestruct = collectSBufDestructTimeStats(); |
80 | mbsizesatdestruct = collectMemBlobDestructTimeStats(); | |
9b74279f FC |
81 | } |
82 | ||
47ba817c | 83 | static void |
ced8def3 | 84 | statHistSBufDumper(StoreEntry * sentry, int, double val, double size, int count) |
47ba817c FC |
85 | { |
86 | if (count == 0) | |
87 | return; | |
88 | storeAppendPrintf(sentry, "\t%d-%d\t%d\n", static_cast<int>(val), static_cast<int>(val+size), count); | |
89 | } | |
90 | ||
9b74279f FC |
91 | void |
92 | SBufStatsAction::dump(StoreEntry* entry) | |
93 | { | |
7e10ac87 | 94 | PackableStream ses(*entry); |
ff1eb053 | 95 | ses << "\n\n\nThese statistics are experimental; their format and contents " |
f53969cc SM |
96 | "should not be relied upon, they are bound to change as " |
97 | "the SBuf feature is evolved\n"; | |
9b74279f FC |
98 | sbdata.dump(ses); |
99 | mbdata.dump(ses); | |
ff1eb053 FC |
100 | ses << "\n"; |
101 | ses << "SBuf size distribution at destruct time:\n"; | |
47ba817c | 102 | sbsizesatdestruct.dump(entry,statHistSBufDumper); |
21a8baf1 | 103 | ses << "MemBlob capacity distribution at destruct time:\n"; |
47ba817c | 104 | mbsizesatdestruct.dump(entry,statHistSBufDumper); |
9b74279f FC |
105 | } |
106 | ||
107 | void | |
108 | SBufStatsAction::pack(Ipc::TypedMsgHdr& msg) const | |
109 | { | |
110 | msg.setType(Ipc::mtCacheMgrResponse); | |
111 | msg.putPod(sbdata); | |
112 | msg.putPod(mbdata); | |
113 | } | |
114 | ||
115 | void | |
116 | SBufStatsAction::unpack(const Ipc::TypedMsgHdr& msg) | |
117 | { | |
118 | msg.checkType(Ipc::mtCacheMgrResponse); | |
119 | msg.getPod(sbdata); | |
120 | msg.getPod(mbdata); | |
121 | } | |
122 | ||
6c974556 HN |
123 | void |
124 | SBufStatsAction::RegisterWithCacheManager() | |
125 | { | |
f079ed87 AR |
126 | SBufStats::MemBlobSizeAtDestructRecorder = &recordMemBlobSizeAtDestruct; |
127 | SBufStats::SBufSizeAtDestructRecorder = &recordSBufSizeAtDestruct; | |
9e167fa2 | 128 | Mgr::RegisterAction("sbuf", "String-Buffer statistics", &SBufStatsAction::Create, 0, 1); |
6c974556 | 129 | } |
ee98780a | 130 |