r26423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26422‎ | r26423 | r26424 >
Date:00:27, 5 October 2007
Author:gmaxwell
Status:old
Tags:
Comment:
Syncing up my local codebase
Modified paths:
  • /trunk/tools/counter/fast_counter.c (modified) (history)

Diff [purge]

Index: trunk/tools/counter/fast_counter.c
@@ -15,7 +15,7 @@
1616 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1717 *
1818 * Compilation:
19 - * gcc -static -O3 -o fast_counter fast_counter.c -lJudy -lm
 19+ * gcc -static -O3 -o fast_counter fast_counter.c -lJudy -lm
2020 *
2121 * Usage:
2222 * ./fast_counter factor hourlythreshold dailythreshold weeklythreshold
@@ -53,10 +53,89 @@
5454 #define GETFIELD 7
5555 #define TIMEFIELD 2
5656 #define URLFIELD 8
 57+#define IPFIELD 4
5758
 59+
 60+Word_t ipaddr;
5861 uint8_t inbuffer[MAXINPUT];
5962 uint8_t buffer[MAXINPUT];
 63+uint8_t host[64];
6064
 65+
 66+
 67+int
 68+freeJSI (Pvoid_t agg)
 69+{
 70+ Pvoid_t iarray;
 71+ PWord_t value;
 72+ uint8_t fbuffer[MAXINPUT];
 73+ Word_t Bytes = 0;
 74+
 75+ fbuffer[0] = '\0';
 76+ if (agg)
 77+ {
 78+ JSLF (value, agg, fbuffer);
 79+ while (value != NULL)
 80+ {
 81+ iarray = (Pvoid_t) * value;
 82+ JLFA (Bytes, iarray);
 83+ JSLN (value, agg, fbuffer);
 84+ }
 85+ JSLFA (Bytes, agg);
 86+ }
 87+ return 0;
 88+}
 89+
 90+int
 91+freeJSS (Pvoid_t agg)
 92+{
 93+ Pvoid_t iarray;
 94+ PWord_t value;
 95+ uint8_t fbuffer[MAXINPUT];
 96+ Word_t Bytes = 0;
 97+
 98+ fbuffer[0] = '\0';
 99+ if (agg)
 100+ {
 101+ JSLF (value, agg, fbuffer);
 102+ while (value != NULL)
 103+ {
 104+ iarray = (Pvoid_t) * value;
 105+ JSLFA (Bytes, iarray);
 106+ JSLN (value, agg, fbuffer);
 107+ }
 108+ JSLFA (Bytes, agg);
 109+ }
 110+ return 0;
 111+}
 112+
 113+int
 114+freeJS1 (Pvoid_t agg)
 115+{
 116+ Pvoid_t iarray;
 117+ PWord_t value;
 118+ uint8_t fbuffer[MAXINPUT];
 119+ Word_t Bytes = 0;
 120+ Word_t TBytes = 0;
 121+
 122+ fbuffer[0] = '\0';
 123+ if (agg)
 124+ {
 125+ JSLF (value, agg, fbuffer);
 126+ while (value != NULL)
 127+ {
 128+ iarray = (Pvoid_t) * value;
 129+ J1FA (Bytes, iarray);
 130+ TBytes += Bytes;
 131+ JSLN (value, agg, fbuffer);
 132+ }
 133+ JSLFA (Bytes, agg);
 134+ TBytes += Bytes;
 135+ }
 136+ return 0;
 137+}
 138+
 139+
61140 void
62141 dumpAgg (Pvoid_t agg, int aggType, int thresh, int ftime, int ltime)
63142 {
@@ -183,9 +262,9 @@
184263 char *hbuf;
185264
186265 char timestamp[32];
187 - char host[64];
188266 char page[256];
189267 int i;
 268+ char *x;
190269
191270 char *result = NULL;
192271
@@ -205,6 +284,24 @@
206285 strncpy (timestamp, result, 32);
207286 break;
208287
 288+ case IPFIELD:
 289+ if (strlen (result) < 8)
 290+ return -1;
 291+ ipaddr = 0;
 292+ ipaddr += (strtol (result, &x, 10) << 24);
 293+ if (result == x)
 294+ return -1;
 295+ ipaddr += (strtol (x + 1, &x, 10) << 16);
 296+ if (result == x)
 297+ return -1;
 298+ ipaddr += (strtol (x + 1, &x, 10) << 8);
 299+ if (result == x)
 300+ return -1;
 301+ ipaddr += strtol (x + 1, &x, 10);
 302+ if (result == x)
 303+ return -1;
 304+ break;
 305+
209306 case URLFIELD:
210307 if (strlen (result) <= 9 || strncmp ("http://", result, 7) != 0)
211308 return -1;
@@ -241,10 +338,13 @@
242339 int
243340 main (int argc, char *argv[])
244341 {
245 - Pvoid_t aggHour = (Pvoid_t) NULL; // hour array
246 - Pvoid_t aggDay = (Pvoid_t) NULL; // day array
247 - Pvoid_t aggWeek = (Pvoid_t) NULL; // week array
 342+ Pvoid_t aggHour = (Pvoid_t) NULL; /* hour array */
 343+ Pvoid_t aggDay = (Pvoid_t) NULL; /* day array */
 344+ Pvoid_t aggWeek = (Pvoid_t) NULL; /* week array */
248345
 346+ Pvoid_t aggSiteUnqW = (Pvoid_t) NULL; /* per site unique visitors per week */
 347+ Pvoid_t uniqsite;
 348+
249349 pid_t aggHourpid = -1;
250350 pid_t aggDaypid = -1;
251351 pid_t aggWeekpid = -1;
@@ -255,7 +355,8 @@
256356
257357 int sampleRate;
258358
259 - PWord_t value; // item counter pointer
 359+
 360+ PWord_t value;
260361 Word_t Bytes;
261362 int linetime;
262363
@@ -265,6 +366,7 @@
266367 exit (1);
267368 }
268369
 370+
269371 sampleRate = atoi (argv[1]);
270372
271373 signal (SIGCHLD, SIG_IGN);
@@ -281,7 +383,7 @@
282384 if (aggWeekStart == 0)
283385 aggWeekStart = linetime;
284386
285 - //Handle Hourly aggregate
 387+ /*Handle Hourly aggregate */
286388 if (linetime >= aggHourStart + 3600)
287389 {
288390 waitpid (aggHourpid, NULL, 1);
@@ -291,9 +393,12 @@
292394 dumpAgg (aggHour, 0, atoi (argv[2]), aggHourStart,
293395 aggHourStart + 3600);
294396 }
295 - JSLFA (Bytes, aggHour); // free array
296 -// fprintf (stderr,"Freed %lu bytes of memory from hourly aggregate.\n", Bytes);
297 -
 397+ JSLFA (Bytes, aggHour);
 398+#ifdef DEBUG
 399+ fprintf (stderr,
 400+ "Freed %lu bytes of memory from hourly aggregate.\n",
 401+ Bytes);
 402+#endif
298403 aggHour = NULL;
299404 aggHourStart = aggHourStart + 3600;
300405 }
@@ -305,7 +410,7 @@
306411 }
307412 (*value) += sampleRate;
308413
309 - //Handle daily aggregate
 414+ /*Handle daily aggregate */
310415 if (linetime >= aggDayStart + 86400)
311416 {
312417 waitpid (aggDaypid, NULL, 1);
@@ -315,9 +420,12 @@
316421 dumpAgg (aggDay, 1, atoi (argv[3]), aggDayStart,
317422 aggDayStart + 86400);
318423 }
319 - JSLFA (Bytes, aggDay); // free array
320 -// fprintf (stderr,"Freed %lu bytes of memory from daily aggregate.\n", Bytes);
321 -
 424+ JSLFA (Bytes, aggDay);
 425+#ifdef DEBUG
 426+ fprintf (stderr,
 427+ "Freed %lu bytes of memory from daily aggregate.\n",
 428+ Bytes);
 429+#endif
322430 aggDay = NULL;
323431 aggDayStart = aggDayStart + 86400;
324432 }
@@ -329,7 +437,7 @@
330438 }
331439 (*value) += sampleRate;
332440
333 - //Handle weekly aggregate
 441+ /*Handle weekly aggregate */
334442 if (linetime >= aggWeekStart + (86400 * 7))
335443 {
336444 waitpid (aggWeekpid, NULL, 1);
@@ -339,10 +447,15 @@
340448 dumpAgg (aggWeek, 2, atoi (argv[4]), aggWeekStart,
341449 aggWeekStart + (86400 * 7));
342450 }
343 - JSLFA (Bytes, aggWeek); // free array
344 -// fprintf (stderr,"Freed %lu bytes of memory from weekly aggregate.\n", Bytes);
345 -
 451+ JSLFA (Bytes, aggWeek);
 452+ freeJS1 (aggSiteUnqW);
 453+#ifdef DEBUG
 454+ fprintf (stderr,
 455+ "Freed %lu bytes of memory from weekly aggregate.\n",
 456+ Bytes);
 457+#endif
346458 aggWeek = NULL;
 459+ aggSiteUnqW = NULL;
347460 aggWeekStart = aggWeekStart + (86400 * 7);
348461 }
349462 JSLI (value, aggWeek, buffer);
@@ -353,6 +466,15 @@
354467 }
355468 (*value) += sampleRate;
356469
 470+ JSLI (value, aggSiteUnqW, host);
 471+ if (value == PJERR)
 472+ {
 473+ printf ("-EMALLOCBOOM\n");
 474+ exit (1);
 475+ }
 476+ uniqsite = (Pvoid_t) * value;
 477+ J1S (Bytes, uniqsite, ipaddr);
 478+ (*value) = (Word_t) uniqsite;
357479 }
358480 }
359481 waitpid (aggWeekpid, NULL, 1);

Status & tagging log