]>
Commit | Line | Data |
---|---|---|
8822ebee AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 16 Cache Manager API | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "config.h" | |
9 | #include "base/TextException.h" | |
10 | #include "HttpReply.h" | |
11 | #include "ipc/Messages.h" | |
12 | #include "ipc/TypedMsgHdr.h" | |
13 | #include "mgr/Filler.h" | |
14 | #include "mgr/InfoAction.h" | |
15 | #include "mgr/Request.h" | |
16 | #include "mgr/Response.h" | |
17 | #include "SquidTime.h" | |
18 | #include "Store.h" | |
19 | ||
20 | ||
21 | extern void GetInfo(Mgr::InfoActionData& stats); | |
22 | extern void DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry); | |
23 | extern void DumpMallocStatistics(StoreEntry* sentry); | |
24 | ||
25 | Mgr::InfoActionData::InfoActionData() | |
26 | { | |
27 | xmemset(this, 0, sizeof(*this)); | |
28 | } | |
29 | ||
30 | Mgr::InfoActionData& | |
31 | Mgr::InfoActionData::operator += (const InfoActionData& stats) | |
32 | { | |
33 | if (!timerisset(&squid_start) || timercmp(&squid_start, &stats.squid_start, >)) | |
34 | squid_start = stats.squid_start; | |
35 | if (timercmp(¤t_time, &stats.current_time, <)) | |
36 | current_time = stats.current_time; | |
37 | client_http_clients += stats.client_http_clients; | |
38 | client_http_requests += stats.client_http_requests; | |
39 | icp_pkts_recv += stats.icp_pkts_recv; | |
40 | icp_pkts_sent += stats.icp_pkts_sent; | |
41 | icp_replies_queued += stats.icp_replies_queued; | |
42 | #if USE_HTCP | |
43 | htcp_pkts_recv += stats.htcp_pkts_recv; | |
44 | htcp_pkts_sent += stats.htcp_pkts_sent; | |
45 | #endif | |
46 | request_failure_ratio += stats.request_failure_ratio; | |
47 | avg_client_http_requests += stats.avg_client_http_requests; | |
48 | avg_icp_messages += stats.avg_icp_messages; | |
49 | select_loops += stats.select_loops; | |
50 | avg_loop_time += stats.avg_loop_time; | |
51 | request_hit_ratio5 += stats.request_hit_ratio5; | |
52 | request_hit_ratio60 += stats.request_hit_ratio60; | |
53 | byte_hit_ratio5 += stats.byte_hit_ratio5; | |
54 | byte_hit_ratio60 += stats.byte_hit_ratio60; | |
55 | request_hit_mem_ratio5 += stats.request_hit_mem_ratio5; | |
56 | request_hit_mem_ratio60 += stats.request_hit_mem_ratio60; | |
57 | request_hit_disk_ratio5 += stats.request_hit_disk_ratio5; | |
58 | request_hit_disk_ratio60 += stats.request_hit_disk_ratio60; | |
59 | store_swap_size += stats.store_swap_size; | |
60 | store_swap_max_size += stats.store_swap_max_size; | |
61 | store_mem_size += stats.store_mem_size; | |
62 | store_pages_max += stats.store_pages_max; | |
63 | store_mem_used += stats.store_mem_used; | |
64 | objects_size += stats.objects_size; | |
65 | unlink_requests += stats.unlink_requests; | |
66 | http_requests5 += stats.http_requests5; | |
67 | http_requests60 += stats.http_requests60; | |
68 | cache_misses5 += stats.cache_misses5; | |
69 | cache_misses60 += stats.cache_misses60; | |
70 | cache_hits5 += stats.cache_hits5; | |
71 | cache_hits60 += stats.cache_hits60; | |
72 | near_hits5 += stats.near_hits5; | |
73 | near_hits60 += stats.near_hits60; | |
74 | not_modified_replies5 += stats.not_modified_replies5; | |
75 | not_modified_replies60 += stats.not_modified_replies60; | |
76 | dns_lookups5 += stats.dns_lookups5; | |
77 | dns_lookups60 += stats.dns_lookups60; | |
78 | icp_queries5 += stats.icp_queries5; | |
79 | icp_queries60 += stats.icp_queries60; | |
80 | if (stats.up_time > up_time) | |
81 | up_time = stats.up_time; | |
82 | cpu_time += stats.cpu_time; | |
83 | cpu_usage += stats.cpu_usage; | |
84 | cpu_usage5 += stats.cpu_usage5; | |
85 | cpu_usage60 += stats.cpu_usage60; | |
86 | #if HAVE_SBRK | |
87 | proc_data_seg += stats.proc_data_seg; | |
88 | #endif | |
89 | maxrss += stats.maxrss; | |
90 | page_faults += stats.page_faults; | |
91 | #if HAVE_MSTATS && HAVE_GNUMALLOC_H | |
92 | ms_bytes_total += stats.ms_bytes_total; | |
93 | ms_bytes_free += stats.ms_bytes_free; | |
94 | #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO | |
95 | mp_arena += stats.mp_arena; | |
96 | mp_uordblks += stats.mp_uordblks; | |
97 | mp_ordblks += stats.mp_ordblks; | |
98 | mp_usmblks += stats.mp_usmblks; | |
99 | mp_smblks += stats.mp_smblks; | |
100 | mp_hblkhd += stats.mp_hblkhd; | |
101 | mp_hblks += stats.mp_hblks; | |
102 | mp_fsmblks += stats.mp_fsmblks; | |
103 | mp_fordblks += stats.mp_fordblks; | |
104 | #if HAVE_STRUCT_MALLINFO_MXFAST | |
105 | mp_mxfast += stats.mp_mxfast; | |
106 | mp_nlblks += stats.mp_nlblks; | |
107 | mp_grain += stats.mp_grain; | |
108 | mp_uordbytes += stats.mp_uordbytes; | |
109 | mp_allocated += stats.mp_allocated; | |
110 | mp_treeoverhead += stats.mp_treeoverhead; | |
111 | #endif | |
112 | #endif | |
113 | total_accounted += stats.total_accounted; | |
114 | #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO | |
115 | mem_pool_allocated += stats.mem_pool_allocated; | |
116 | #endif | |
117 | gb_saved_count += stats.gb_saved_count; | |
118 | gb_freed_count += stats.gb_freed_count; | |
119 | max_fd += stats.max_fd; | |
120 | biggest_fd += stats.biggest_fd; | |
121 | number_fd += stats.number_fd; | |
122 | opening_fd += stats.opening_fd; | |
123 | num_fd_free += stats.num_fd_free; | |
124 | reserved_fd += stats.reserved_fd; | |
125 | store_open_disk_fd += stats.store_open_disk_fd; | |
126 | store_entries += stats.store_entries; | |
127 | store_mem_entries += stats.store_mem_entries; | |
128 | hot_obj_count += stats.hot_obj_count; | |
129 | n_disk_objects += stats.n_disk_objects; | |
130 | ++count; | |
131 | ||
132 | return *this; | |
133 | } | |
134 | ||
135 | Mgr::InfoAction::Pointer | |
136 | Mgr::InfoAction::Create(const CommandPointer &cmd) | |
137 | { | |
138 | return new InfoAction(cmd); | |
139 | } | |
140 | ||
141 | Mgr::InfoAction::InfoAction(const CommandPointer &cmd): | |
142 | Action(cmd), data() | |
143 | { | |
144 | debugs(16, 5, HERE); | |
145 | } | |
146 | ||
147 | void | |
148 | Mgr::InfoAction::add(const Action& action) | |
149 | { | |
150 | debugs(16, 5, HERE); | |
151 | data += dynamic_cast<const InfoAction&>(action).data; | |
152 | } | |
153 | ||
154 | void | |
155 | Mgr::InfoAction::respond(const Request& request) | |
156 | { | |
157 | debugs(16, 5, HERE); | |
158 | int fd = ImportHttpFdIntoComm(request.fd); | |
159 | Must(fd >= 0); | |
160 | Must(request.requestId != 0); | |
161 | AsyncJob::Start(new Mgr::Filler(this, fd, request.requestId)); | |
162 | } | |
163 | ||
164 | void | |
165 | Mgr::InfoAction::collect() | |
166 | { | |
167 | GetInfo(data); | |
168 | } | |
169 | ||
170 | void | |
171 | Mgr::InfoAction::dump(StoreEntry* entry) | |
172 | { | |
173 | debugs(16, 5, HERE); | |
174 | Must(entry != NULL); | |
175 | ||
176 | #if XMALLOC_STATISTICS | |
177 | if (UsingSmp() && IamWorkerProcess()) | |
178 | storeAppendPrintf(entry, "by kid%d {\n", KidIdentifier); | |
179 | DumpMallocStatistics(entry); | |
180 | if (UsingSmp() && IamWorkerProcess()) | |
181 | storeAppendPrintf(entry, "} by kid%d\n\n", KidIdentifier); | |
182 | #endif | |
183 | if (IamPrimaryProcess()) | |
184 | DumpInfo(data, entry); | |
185 | } | |
186 | ||
187 | void | |
188 | Mgr::InfoAction::pack(Ipc::TypedMsgHdr& msg) const | |
189 | { | |
190 | msg.setType(Ipc::mtCacheMgrResponse); | |
191 | msg.putPod(data); | |
192 | } | |
193 | ||
194 | void | |
195 | Mgr::InfoAction::unpack(const Ipc::TypedMsgHdr& msg) | |
196 | { | |
197 | msg.checkType(Ipc::mtCacheMgrResponse); | |
198 | msg.getPod(data); | |
199 | } |