~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/cache/CachePagesInternal.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
#include "P_Cache.h"
 
25
 
 
26
#ifdef NON_MODULAR
 
27
#include "Show.h"
 
28
 
 
29
struct ShowCacheInternal: public ShowCont
 
30
{
 
31
  int part_index;
 
32
  int seg_index;
 
33
  CacheKey show_cache_key;
 
34
  CacheVC *cache_vc;
 
35
 
 
36
 
 
37
  int showMain(int event, Event * e);
 
38
  int showEvacuations(int event, Event * e);
 
39
  int showPartEvacuations(int event, Event * e);
 
40
  int showPartitions(int event, Event * e);
 
41
  int showPartPartitions(int event, Event * e);
 
42
  int showSegments(int event, Event * e);
 
43
  int showSegSegment(int event, Event * e);
 
44
#ifdef CACHE_STAT_PAGES
 
45
  int showConnections(int event, Event * e);
 
46
  int showPartConnections(int event, Event * e);
 
47
#endif
 
48
 
 
49
    ShowCacheInternal(Continuation * c, HTTPHdr * h):ShowCont(c, h), part_index(0), seg_index(0)
 
50
  {
 
51
    SET_HANDLER(&ShowCacheInternal::showMain);
 
52
  };
 
53
 
 
54
  ~ShowCacheInternal() {
 
55
  }
 
56
 
 
57
};
 
58
extern ShowCacheInternal *theshowcacheInternal;
 
59
Action *register_ShowCacheInternal(Continuation * c, HTTPHdr * h);
 
60
 
 
61
 
 
62
 
 
63
 
 
64
extern Part **gpart;
 
65
extern volatile int gnpart;
 
66
 
 
67
 
 
68
// Stat Pages
 
69
ShowCacheInternal *theshowcacheInternal = NULL;
 
70
 
 
71
 
 
72
#define STREQ_PREFIX(_x,_s) (!strncasecmp(_x,_s,sizeof(_s)-1))
 
73
#define STREQ_LEN_PREFIX(_x,_l,_s) (path_len < sizeof(_s) && !strncasecmp(_x,_s,sizeof(_s)-1))
 
74
 
 
75
 
 
76
Action *
 
77
register_ShowCacheInternal(Continuation * c, HTTPHdr * h)
 
78
{
 
79
  theshowcacheInternal = NEW(new ShowCacheInternal(c, h));
 
80
  URL *u = h->url_get();
 
81
 
 
82
  int path_len;
 
83
  const char *path = u->path_get(&path_len);
 
84
 
 
85
  if (!path) {
 
86
  }
 
87
#ifdef CACHE_STAT_PAGES
 
88
  else if (STREQ_LEN_PREFIX(path, path_len, "connections")) {
 
89
    SET_CONTINUATION_HANDLER(theshowcacheInternal, &ShowCacheInternal::showConnections);
 
90
  }
 
91
#endif
 
92
  else if (STREQ_PREFIX(path, "evacuations")) {
 
93
    SET_CONTINUATION_HANDLER(theshowcacheInternal, &ShowCacheInternal::showEvacuations);
 
94
  } else if (STREQ_PREFIX(path, "partitions")) {
 
95
    SET_CONTINUATION_HANDLER(theshowcacheInternal, &ShowCacheInternal::showPartitions);
 
96
  }
 
97
 
 
98
  if (theshowcacheInternal->mutex->thread_holding)
 
99
    CONT_SCHED_LOCK_RETRY(theshowcacheInternal);
 
100
  else
 
101
    eventProcessor.schedule_imm(theshowcacheInternal, ET_NET);
 
102
  return &theshowcacheInternal->action;
 
103
}
 
104
 
 
105
 
 
106
int
 
107
ShowCacheInternal::showMain(int event, Event * e)
 
108
{
 
109
  CHECK_SHOW(begin("Cache"));
 
110
#ifdef CACHE_STAT_PAGES
 
111
  CHECK_SHOW(show("<H3>Show <A HREF=\"./connections\">Connections</A></H3>\n"
 
112
                  "<H3>Show <A HREF=\"./evacuations\">Evacuations</A></H3>\n"
 
113
                  "<H3>Show <A HREF=\"./partitions\">Partitions</A></H3>\n"));
 
114
#else
 
115
  CHECK_SHOW(show("<H3>Show <A HREF=\"./evacuations\">Evacuations</A></H3>\n"
 
116
                  "<H3>Show <A HREF=\"./partitions\">Partitions</A></H3>\n"));
 
117
#endif
 
118
  return complete(event, e);
 
119
}
 
120
 
 
121
#ifdef CACHE_STAT_PAGES
 
122
int
 
123
ShowCacheInternal::showConnections(int event, Event * e)
 
124
{
 
125
  CHECK_SHOW(begin("Cache VConnections"));
 
126
  CHECK_SHOW(show("<H3>Cache Connections</H3>\n"
 
127
                  "<table border=1><tr>"
 
128
                  "<th>Operation</th>"
 
129
                  "<th>Partition</th>"
 
130
                  "<th>URL/Hash</th>" "<th>Bytes Done</th>" "<th>Total Bytes</th>" "<th>Bytes Todo</th>" "</tr>\n"));
 
131
 
 
132
  SET_HANDLER(&ShowCacheInternal::showPartConnections);
 
133
  CONT_SCHED_LOCK_RETRY_RET(this);
 
134
}
 
135
 
 
136
 
 
137
int
 
138
ShowCacheInternal::showPartConnections(int event, Event * e)
 
139
{
 
140
  CACHE_TRY_LOCK(lock, gpart[part_index]->mutex, mutex->thread_holding);
 
141
  if (!lock) {
 
142
    CONT_SCHED_LOCK_RETRY_RET(this);
 
143
  }
 
144
  for (CacheVC * vc = (CacheVC *) gpart[part_index]->stat_cache_vcs.head; vc; vc = vc->stat_link.next) {
 
145
 
 
146
    char nbytes[60], todo[60], url[81092];
 
147
    int ib = 0, xd = 0;
 
148
    URL uu;
 
149
 
 
150
    MUTEX_LOCK(lock2, vc->mutex, mutex->thread_holding);
 
151
    // if vc is closed ignore - Ramki 08/30/2000
 
152
    if (vc->closed == 1)
 
153
      continue;
 
154
    sprintf(nbytes, "%d", vc->vio.nbytes);
 
155
    sprintf(todo, "%d", vc->vio.ntodo());
 
156
 
 
157
    if (vc->f.frag_type == CACHE_FRAG_TYPE_HTTP && vc->request.valid()) {
 
158
      URL *u = vc->request.url_get(&uu);
 
159
      u->print(url, 8000, &ib, &xd);
 
160
      url[ib] = 0;
 
161
    } else if (vc->alternate.valid()) {
 
162
      URL *u = vc->alternate.request_url_get(&uu);
 
163
      u->print(url, 8000, &ib, &xd);
 
164
      url[ib] = 0;
 
165
    } else
 
166
      vc->key.string(url);
 
167
    CHECK_SHOW(show("<tr>" "<td>%s</td>"        // operation
 
168
                    "<td>%s</td>"       // Part
 
169
                    "<td>%s</td>"       // URL/Hash
 
170
                    "<td>%d</td>"
 
171
                    "<td>%s</td>"
 
172
                    "<td>%s</td>"
 
173
                    "</tr>\n",
 
174
                    ((vc->vio.op == VIO::READ) ? "Read" : "Write"),
 
175
                    vc->part->hash_id,
 
176
                    url,
 
177
                    vc->vio.ndone,
 
178
                    vc->vio.nbytes == INT64_MAX ? "all" : nbytes, vc->vio.nbytes == INT64_MAX ? "all" : todo));
 
179
  }
 
180
  part_index++;
 
181
  if (part_index < gnpart)
 
182
    CONT_SCHED_LOCK_RETRY(this);
 
183
  else {
 
184
    CHECK_SHOW(show("</table>\n"));
 
185
    return complete(event, e);
 
186
  }
 
187
  return EVENT_CONT;
 
188
}
 
189
 
 
190
#endif
 
191
 
 
192
 
 
193
int
 
194
ShowCacheInternal::showEvacuations(int event, Event * e)
 
195
{
 
196
  CHECK_SHOW(begin("Cache Pending Evacuations"));
 
197
  CHECK_SHOW(show("<H3>Cache Evacuations</H3>\n"
 
198
                  "<table border=1><tr>"
 
199
                  "<th>Offset</th>" "<th>Estimated Size</th>" "<th>Reader Count</th>" "<th>Done</th>" "</tr>\n"));
 
200
 
 
201
  SET_HANDLER(&ShowCacheInternal::showPartEvacuations);
 
202
  CONT_SCHED_LOCK_RETRY_RET(this);
 
203
}
 
204
 
 
205
 
 
206
int
 
207
ShowCacheInternal::showPartEvacuations(int event, Event * e)
 
208
{
 
209
  Part *p = gpart[part_index];
 
210
  CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding);
 
211
  if (!lock)
 
212
    CONT_SCHED_LOCK_RETRY_RET(this);
 
213
 
 
214
  EvacuationBlock *b;
 
215
  int last = (p->len - (p->start - p->skip)) / EVACUATION_BUCKET_SIZE;
 
216
  for (int i = 0; i < last; i++) {
 
217
    for (b = p->evacuate[i].head; b; b = b->link.next) {
 
218
      char offset[60];
 
219
      sprintf(offset, "%" PRIu64 "", (uint64_t) part_offset(p, &b->dir));
 
220
      CHECK_SHOW(show("<tr>" "<td>%s</td>"      // offset
 
221
                      "<td>%d</td>"     // estimated size
 
222
                      "<td>%d</td>"     // reader count
 
223
                      "<td>%s</td>"     // done
 
224
                      "</tr>\n", offset, (int) dir_approx_size(&b->dir), b->readers, b->f.done ? "yes" : "no"));
 
225
    }
 
226
  }
 
227
  part_index++;
 
228
  if (part_index < gnpart)
 
229
    CONT_SCHED_LOCK_RETRY(this);
 
230
  else {
 
231
    CHECK_SHOW(show("</table>\n"));
 
232
    return complete(event, e);
 
233
  }
 
234
  return EVENT_CONT;
 
235
}
 
236
 
 
237
int
 
238
ShowCacheInternal::showPartitions(int event, Event * e)
 
239
{
 
240
  CHECK_SHOW(begin("Cache Partitions"));
 
241
  CHECK_SHOW(show("<H3>Cache Partitions</H3>\n"
 
242
                  "<table border=1><tr>"
 
243
                  "<th>ID</th>"
 
244
                  "<th>Blocks</th>"
 
245
                  "<th>Directory Entries</th>"
 
246
                  "<th>Write Position</th>"
 
247
                  "<th>Write Agg Todo</th>"
 
248
                  "<th>Write Agg Todo Size</th>"
 
249
                  "<th>Write Agg Done</th>"
 
250
                  "<th>Phase</th>" "<th>Create Time</th>" "<th>Sync Serial</th>" "<th>Write Serial</th>" "</tr>\n"));
 
251
 
 
252
  SET_HANDLER(&ShowCacheInternal::showPartPartitions);
 
253
  CONT_SCHED_LOCK_RETRY_RET(this);
 
254
}
 
255
 
 
256
 
 
257
int
 
258
ShowCacheInternal::showPartPartitions(int event, Event * e)
 
259
{
 
260
  Part *p = gpart[part_index];
 
261
  CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding);
 
262
  if (!lock)
 
263
    CONT_SCHED_LOCK_RETRY_RET(this);
 
264
 
 
265
  char ctime[256];
 
266
  ink_ctime_r(&p->header->create_time, ctime);
 
267
  ctime[strlen(ctime) - 1] = 0;
 
268
  int agg_todo = 0;
 
269
  int agg_done = p->agg_buf_pos;
 
270
  CacheVC *c = 0;
 
271
  for (c = p->agg.head; c; c = (CacheVC *) c->link.next)
 
272
    agg_todo++;
 
273
  CHECK_SHOW(show("<tr>" "<td>%s</td>"  // ID
 
274
                  "<td>%" PRId64 "</td>" // blocks
 
275
                  "<td>%" PRId64 "</td>" // directory entries
 
276
                  "<td>%" PRId64 "</td>" // write position
 
277
                  "<td>%d</td>" // write agg to do
 
278
                  "<td>%d</td>" // write agg to do size
 
279
                  "<td>%d</td>" // write agg done
 
280
                  "<td>%d</td>" // phase
 
281
                  "<td>%s</td>" // create time
 
282
                  "<td>%u</td>" // sync serial
 
283
                  "<td>%u</td>" // write serial
 
284
                  "</tr>\n",
 
285
                  p->hash_id,
 
286
                  (uint64_t)((p->len - (p->start - p->skip)) / CACHE_BLOCK_SIZE),
 
287
                  (uint64_t)(p->buckets * DIR_DEPTH * p->segments),
 
288
                  (uint64_t)((p->header->write_pos - p->start) / CACHE_BLOCK_SIZE),
 
289
                  agg_todo,
 
290
                  p->agg_todo_size,
 
291
                  agg_done, p->header->phase, ctime, p->header->sync_serial, p->header->write_serial));
 
292
  CHECK_SHOW(show("</table>\n"));
 
293
  SET_HANDLER(&ShowCacheInternal::showSegments);
 
294
  return showSegments(event, e);
 
295
}
 
296
 
 
297
int
 
298
ShowCacheInternal::showSegments(int event, Event * e)
 
299
{
 
300
  CHECK_SHOW(show("<H3>Cache Partition Segments</H3>\n"
 
301
                  "<table border=1><tr>"
 
302
                  "<th>Free</th>"
 
303
                  "<th>Used</th>"
 
304
                  "<th>Empty</th>" "<th>Valid</th>" "<th>Agg Valid</th>" "<th>Avg Size</th>" "</tr>\n"));
 
305
 
 
306
  SET_HANDLER(&ShowCacheInternal::showSegSegment);
 
307
  seg_index = 0;
 
308
  CONT_SCHED_LOCK_RETRY_RET(this);
 
309
}
 
310
 
 
311
int
 
312
ShowCacheInternal::showSegSegment(int event, Event * e)
 
313
{
 
314
  Part *p = gpart[part_index];
 
315
  CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding);
 
316
  if (!lock)
 
317
    CONT_SCHED_LOCK_RETRY_RET(this);
 
318
  int free = 0, used = 0, empty = 0, valid = 0, agg_valid = 0, avg_size = 0;
 
319
  dir_segment_accounted(seg_index, p, 0, &free, &used, &empty, &valid, &agg_valid, &avg_size);
 
320
  CHECK_SHOW(show("<tr>"
 
321
                  "<td>%d</td>"
 
322
                  "<td>%d</td>"
 
323
                  "<td>%d</td>"
 
324
                  "<td>%d</td>" "<td>%d</td>" "<td>%d</td>" "</tr>\n", free, used, empty, valid, agg_valid, avg_size));
 
325
  seg_index++;
 
326
  if (seg_index < p->segments)
 
327
    CONT_SCHED_LOCK_RETRY(this);
 
328
  else {
 
329
    CHECK_SHOW(show("</table>\n"));
 
330
    seg_index = 0;
 
331
    part_index++;
 
332
    if (part_index < gnpart)
 
333
      CONT_SCHED_LOCK_RETRY(this);
 
334
    else
 
335
      return complete(event, e);
 
336
  }
 
337
  return EVENT_CONT;
 
338
}
 
339
 
 
340
 
 
341
 
 
342
#endif // NON_MODULAR