~ubuntu-branches/ubuntu/quantal/apt-cacher-ng/quantal-backports

« back to all changes in this revision

Viewing changes to source/aclogger.cc

  • Committer: Bazaar Package Importer
  • Author(s): Eduard Bloch
  • Date: 2010-07-28 01:17:33 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20100728011733-kocsb0jjhzu76ees
Tags: 0.5.1-1
* New upstream version
  + header inclusion cleanup (closes: #590291)
  + kfreebsd related fixes
  + long outstanding user interface fixes and various regression fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include "lockable.h"
12
12
#include "filereader.h"
13
13
 
14
 
#include <sys/types.h>
15
 
#include <sys/stat.h>
 
14
#include "fileio.h"
16
15
#include <unistd.h>
17
 
#include <glob.h>
18
16
 
19
17
#include <vector>
20
 
#include <iostream>
21
 
 
22
 
#include <stdio.h>
23
 
 
24
18
#include <string.h>
25
19
#include <iostream>
26
20
#include <meta.h>
156
150
        { // needs to be created/updated
157
151
                
158
152
#endif
159
 
                glob_t globbuf;
160
 
 
161
 
                memset(&globbuf, 0, sizeof(glob_t));
162
 
                glob((acfg::logdir+"/apt-cacher*.log").c_str(), GLOB_DOOFFS | GLOB_NOSORT,
163
 
                                NULL, &globbuf);
164
 
 
165
 
                //cout << "wo? " << (acfg::logdir+"/*.log.*").c_str() <<endl;
166
 
                
167
 
                for (unsigned int i=0; i<globbuf.gl_pathc; i++)
 
153
 
 
154
                tStrVec logs=ExpandFilePattern(acfg::logdir +
 
155
                                SZPATHSEP "apt-cacher*.log", false);
 
156
 
 
157
                for (tStrVecIterConst it=logs.begin();it!=logs.end();it++)
168
158
                {
169
159
                        if(acfg::debug)
170
 
                                cerr << "Reading log file: " << globbuf.gl_pathv[i] <<endl; 
 
160
                                cerr << "Reading log file: " << *it <<endl;
171
161
                        filereader reader;
172
 
                        if (!reader.OpenFile(globbuf.gl_pathv[i]))
 
162
                        if (!reader.OpenFile(*it))
173
163
                        {
174
164
                                aclog::err("Error opening a log file");
175
165
                                continue;
216
206
                                 
217
207
                        }
218
208
                }
219
 
                globfree(&globbuf);
220
209
                
221
210
#if 0
222
211
                // Normalize data and repack for user 
262
251
        }
263
252
#endif
264
253
}
265
 
        
 
254
 
 
255
string GetStatReport()
 
256
{
 
257
        string ret;
 
258
        vector<char> buf(1024);
 
259
        vector<aclog::tRowData> data;
 
260
        aclog::GetStats(data);
 
261
        for (vector<aclog::tRowData>::iterator it = data.begin(); it != data.end(); it++)
 
262
        {
 
263
 
 
264
                unsigned long reqMax = max(it->reqIn, it->reqOut);
 
265
                uint64_t dataMax = max(it->byteIn, it->byteOut);
 
266
 
 
267
                if (0 == dataMax || 0 == reqMax)
 
268
                        continue;
 
269
 
 
270
                char tbuf[50];
 
271
                size_t zlen(0);
 
272
                ctime_r(&it->from, tbuf);
 
273
                struct tm *tmp = localtime(&it->from);
 
274
                if (!tmp)
 
275
                        goto time_error;
 
276
                zlen = strftime(tbuf, sizeof(tbuf), TIMEFORMAT, tmp);
 
277
                if (!zlen)
 
278
                        goto time_error;
 
279
 
 
280
                if (it->from != it->to)
 
281
                {
 
282
                        tmp = localtime(&it->to);
 
283
                        if (!tmp)
 
284
                                goto time_error;
 
285
                        if (0 == strftime(tbuf + zlen, sizeof(tbuf) - zlen,
 
286
                                        " - " TIMEFORMAT, tmp))
 
287
                                goto time_error;
 
288
                }
 
289
                snprintf(&buf[0], buf.size(), "<tr bgcolor=\"white\">"
 
290
 
 
291
                        "<td class=\"colcont\">%s</td>"
 
292
 
 
293
                        "<td class=\"coltitle\"><span>&nbsp;</span></td>"
 
294
 
 
295
                        "<td class=\"colcont\">%lu (%2.2f%%)</td>"
 
296
                        "<td class=\"colcont\">%lu (%2.2f%%)</td>"
 
297
                        "<td class=\"colcont\">%lu</td>"
 
298
 
 
299
                        "<td class=\"coltitle\"><span>&nbsp;</span></td>"
 
300
 
 
301
                        "<td class=\"colcont\">%2.2f MiB (%2.2f%%)</td>"
 
302
                        "<td class=\"colcont\">%2.2f MiB (%2.2f%%)</td>"
 
303
                        "<td class=\"colcont\">%2.2f MiB</td>"
 
304
                        "</tr>", tbuf, reqMax - it->reqIn, double(reqMax - it->reqIn)
 
305
                                / reqMax * 100, // hitcount
 
306
                                it->reqIn, double(it->reqIn) / reqMax * 100, // misscount
 
307
                                reqMax,
 
308
 
 
309
                                double(dataMax - it->byteIn) / 1048576, double(dataMax
 
310
                                                - it->byteIn) / dataMax * 100, // hitdata
 
311
                                double(it->byteIn) / 1048576, double(it->byteIn) / dataMax
 
312
                                                * 100, // missdata
 
313
                                double(dataMax) / 1048576
 
314
 
 
315
                ); //, int(it->ratioSent*nRatWid), int((1.0-it->ratioSent)*nRatWid));
 
316
                ret += &buf[0];
 
317
                continue;
 
318
                time_error: ret
 
319
                                += " Invalid time value detected, check the stats database. ";
 
320
        }
 
321
        return ret;
 
322
}
 
323
 
 
324
 
266
325
errnoFmter::errnoFmter()
267
326
{
268
327
        char buf[32];