]>
Commit | Line | Data |
---|---|---|
9b74279f | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 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" | |
dfe4488f | 14 | #include "sbuf/DetailedStats.h" |
9b74279f | 15 | #include "SBufStatsAction.h" |
9b74279f FC |
16 | |
17 | SBufStatsAction::SBufStatsAction(const Mgr::CommandPointer &cmd_): | |
f53969cc | 18 | Action(cmd_) |
9b74279f FC |
19 | { } //default constructor is OK for data member |
20 | ||
21 | SBufStatsAction::Pointer | |
22 | SBufStatsAction::Create(const Mgr::CommandPointer &cmd) | |
23 | { | |
24 | return new SBufStatsAction(cmd); | |
25 | } | |
26 | ||
27 | void | |
28 | SBufStatsAction::add(const Mgr::Action& action) | |
29 | { | |
30 | sbdata += dynamic_cast<const SBufStatsAction&>(action).sbdata; | |
31 | mbdata += dynamic_cast<const SBufStatsAction&>(action).mbdata; | |
ff1eb053 FC |
32 | sbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).sbsizesatdestruct; |
33 | mbsizesatdestruct += dynamic_cast<const SBufStatsAction&>(action).mbsizesatdestruct; | |
9b74279f FC |
34 | } |
35 | ||
36 | void | |
37 | SBufStatsAction::collect() | |
38 | { | |
39 | sbdata = SBuf::GetStats(); | |
40 | mbdata = MemBlob::GetStats(); | |
b3c7741c AR |
41 | sbsizesatdestruct = collectSBufDestructTimeStats(); |
42 | mbsizesatdestruct = collectMemBlobDestructTimeStats(); | |
9b74279f FC |
43 | } |
44 | ||
47ba817c | 45 | static void |
ced8def3 | 46 | statHistSBufDumper(StoreEntry * sentry, int, double val, double size, int count) |
47ba817c FC |
47 | { |
48 | if (count == 0) | |
49 | return; | |
50 | storeAppendPrintf(sentry, "\t%d-%d\t%d\n", static_cast<int>(val), static_cast<int>(val+size), count); | |
51 | } | |
52 | ||
9b74279f FC |
53 | void |
54 | SBufStatsAction::dump(StoreEntry* entry) | |
55 | { | |
7e10ac87 | 56 | PackableStream ses(*entry); |
ff1eb053 | 57 | ses << "\n\n\nThese statistics are experimental; their format and contents " |
f53969cc SM |
58 | "should not be relied upon, they are bound to change as " |
59 | "the SBuf feature is evolved\n"; | |
9b74279f FC |
60 | sbdata.dump(ses); |
61 | mbdata.dump(ses); | |
ff1eb053 FC |
62 | ses << "\n"; |
63 | ses << "SBuf size distribution at destruct time:\n"; | |
47ba817c | 64 | sbsizesatdestruct.dump(entry,statHistSBufDumper); |
21a8baf1 | 65 | ses << "MemBlob capacity distribution at destruct time:\n"; |
47ba817c | 66 | mbsizesatdestruct.dump(entry,statHistSBufDumper); |
9b74279f FC |
67 | } |
68 | ||
69 | void | |
70 | SBufStatsAction::pack(Ipc::TypedMsgHdr& msg) const | |
71 | { | |
72 | msg.setType(Ipc::mtCacheMgrResponse); | |
73 | msg.putPod(sbdata); | |
74 | msg.putPod(mbdata); | |
75 | } | |
76 | ||
77 | void | |
78 | SBufStatsAction::unpack(const Ipc::TypedMsgHdr& msg) | |
79 | { | |
80 | msg.checkType(Ipc::mtCacheMgrResponse); | |
81 | msg.getPod(sbdata); | |
82 | msg.getPod(mbdata); | |
83 | } | |
84 | ||
6c974556 HN |
85 | void |
86 | SBufStatsAction::RegisterWithCacheManager() | |
87 | { | |
88 | Mgr::RegisterAction("sbuf", "String-Buffer statistics", &SBufStatsAction::Create, 0 , 1); | |
89 | } | |
ee98780a | 90 |