SBufStatsAction.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #include "squid.h"
10 #include "base/PackableStream.h"
11 #include "ipc/Messages.h"
12 #include "ipc/TypedMsgHdr.h"
13 #include "mgr/Registration.h"
14 #include "sbuf/Stats.h"
15 #include "SBufStatsAction.h"
16 
18 static StatHist *
20  const auto stats = new StatHist;
21  stats->logInit(100, 30.0, 128000.0);
22  return stats;
23 }
24 
26 static StatHist &
28 {
29  static auto stats = makeDestructTimeHist();
30  return *stats;
31 }
32 
34 static StatHist &
36 {
37  static auto stats = makeDestructTimeHist();
38  return *stats;
39 }
40 
42 static void
43 recordSBufSizeAtDestruct(const size_t sz)
44 {
45  collectSBufDestructTimeStats().count(static_cast<double>(sz));
46 }
47 
49 static void
51 {
52  collectMemBlobDestructTimeStats().count(static_cast<double>(sz));
53 }
54 
56  Action(cmd_)
57 { } //default constructor is OK for data member
58 
61 {
62  return new SBufStatsAction(cmd);
63 }
64 
65 void
67 {
68  sbdata += dynamic_cast<const SBufStatsAction&>(action).sbdata;
69  mbdata += dynamic_cast<const SBufStatsAction&>(action).mbdata;
70  sbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).sbsizesatdestruct;
71  mbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).mbsizesatdestruct;
72 }
73 
74 void
76 {
81 }
82 
83 static void
84 statHistSBufDumper(StoreEntry * sentry, int, double val, double size, int count)
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 
91 void
93 {
94  PackableStream ses(*entry);
95  ses << "\n\n\nThese statistics are experimental; their format and contents "
96  "should not be relied upon, they are bound to change as "
97  "the SBuf feature is evolved\n";
98  sbdata.dump(ses);
99  mbdata.dump(ses);
100  ses << "\n";
101  ses << "SBuf size distribution at destruct time:\n";
103  ses << "MemBlob capacity distribution at destruct time:\n";
105 }
106 
107 void
109 {
111  msg.putPod(sbdata);
112  msg.putPod(mbdata);
113 }
114 
115 void
117 {
119  msg.getPod(sbdata);
120  msg.getPod(mbdata);
121 }
122 
123 void
125 {
128  Mgr::RegisterAction("sbuf", "String-Buffer statistics", &SBufStatsAction::Create, 0, 1);
129 }
130 
void add(const Mgr::Action &action) override
incrementally merge in remote information (of the same action type)
static StatHist & collectMemBlobDestructTimeStats()
the MemBlob size-at-destruct-time histogram
StatHist mbsizesatdestruct
void setType(int aType)
sets message type; use MessageType enum
Definition: TypedMsgHdr.cc:100
StatHist sbsizesatdestruct
void checkType(int aType) const
Definition: TypedMsgHdr.cc:94
void dump(StoreEntry *entry) override
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:855
@ mtCacheMgrResponse
Definition: Messages.h:36
const CommandPointer cmd
the command that caused this action
Definition: Action.h:90
static Pointer Create(const Mgr::CommandPointer &cmd)
Mgr::ClassActionCreationHandler for Mgr::RegisterAction()
void putPod(const Pod &pod)
store POD
Definition: TypedMsgHdr.h:126
static void RegisterWithCacheManager(void)
int size
Definition: ModDevPoll.cc:69
static void recordSBufSizeAtDestruct(const size_t sz)
record the size an SBuf had when it was destructed
static void recordMemBlobSizeAtDestruct(const size_t sz)
record the size a MemBlob had when it was destructed
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
Definition: StatHist.cc:171
std::ostream & dump(std::ostream &os) const
dumps class-wide statistics
Definition: MemBlob.cc:33
SBuf stats for cachemgr.
void count(double val)
Definition: StatHist.cc:55
void collect() override
calculate and keep local action-specific information
SBufStatsAction(const Mgr::CommandPointer &cmd)
static StatHist * makeDestructTimeHist()
creates a new size-at-destruct-time histogram
static const MemBlobStats & GetStats()
obtain a const view of class-wide statistics
Definition: MemBlob.cc:53
static SizeRecorder SBufSizeAtDestructRecorder
collects statistics about SBuf sizes at SBuf destruction time
Definition: Stats.h:64
MemBlobStats mbdata
void unpack(const Ipc::TypedMsgHdr &msg) override
unpack action info from the message received by Coordinator
void pack(Ipc::TypedMsgHdr &msg) const override
pack collected action info into a message to be sent to Coordinator
static StatHist & collectSBufDestructTimeStats()
the SBuf size-at-destruct-time histogram
static SizeRecorder MemBlobSizeAtDestructRecorder
collects statistics about MemBlob capacity at MemBlob destruction time
Definition: Stats.h:66
static const SBufStats & GetStats()
gets global statistic information
Definition: SBuf.cc:494
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
Definition: Registration.cc:54
void logInit(unsigned int capacity, double min, double max)
Definition: StatHist.cc:221
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:34
static void statHistSBufDumper(StoreEntry *sentry, int, double val, double size, int count)
void getPod(Pod &pod) const
load POD
Definition: TypedMsgHdr.h:118
std::ostream & dump(std::ostream &os) const
Dump statistics to an ostream.
Definition: Stats.cc:65

 

Introduction

Documentation

Support

Miscellaneous