~ubuntu-branches/ubuntu/precise/suricata/precise-proposed

« back to all changes in this revision

Viewing changes to src/util-profiling.c

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2010-06-19 17:39:14 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100619173914-5vkjfgz24mbia29z
Tags: 0.9.2-1
ImportedĀ UpstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
int profiling_rules_enabled = 0;
79
79
 
80
80
/**
 
81
 * Used as a check so we don't double enter a profiling run.
 
82
 */
 
83
__thread int profiling_entered = 0;
 
84
 
 
85
/**
81
86
 * \brief Initialize profiling.
82
87
 */
83
88
void
194
199
    uint32_t i;
195
200
    SCProfileSummary summary[rules_pca->size];
196
201
    uint32_t count = rules_pca->size;
 
202
    uint64_t total_ticks = 0;
197
203
 
198
204
    SCLogInfo("Dumping profiling data.");
199
205
 
206
212
                (long double)rules_pca->head[i].syncs;
207
213
        summary[i - 1].checks = rules_pca->head[i].syncs;
208
214
        summary[i - 1].matches = rules_profile_data[i].matches;
 
215
        total_ticks += summary[i - 1].ticks;
209
216
    }
210
217
 
211
218
    switch (profiling_rules_sort_order) {
227
234
        break;
228
235
    }
229
236
 
230
 
    fprintf(output, "  %-12s %-12s %-8s %-8s %-11s\n", "Rule", "Ticks", "Checks", "Matches", "Avg Ticks");
 
237
    fprintf(output, "  %-12s %-12s %-6s %-8s %-8s %-11s\n", "Rule", "Ticks", "%", "Checks", "Matches", "Avg Ticks");
231
238
    fprintf(output, "  ------------ "
232
239
        "------------ "
 
240
        "------ "
233
241
        "-------- "
234
242
        "-------- "
235
243
        "----------- "
236
244
        "\n");
237
245
    for (i = 0; i < MIN(count, profiling_rules_limit); i++) {
238
 
        fprintf(output, "  %-12s %-12"PRIu64" %-8"PRIu64" %-8"PRIu64" %-8.2f\n",
 
246
        double percent = (long double)summary[i].ticks /
 
247
            (long double)total_ticks * 100;
 
248
        fprintf(output,
 
249
            "  %-12s %-12"PRIu64" %-6.2f %-8"PRIu64" %-8"PRIu64" %-8.2f\n",
239
250
            summary[i].name,
240
251
            summary[i].ticks,
 
252
            percent,
241
253
            summary[i].checks,
242
254
            summary[i].matches,
243
255
            summary[i].avgticks);
355
367
    return 1;
356
368
}
357
369
 
 
370
static int
 
371
ProfilingGenericTicksTest01(void) {
 
372
#define TEST_RUNS 1024
 
373
    uint64_t ticks_start = 0;
 
374
    uint64_t ticks_end = 0;
 
375
    void *ptr[TEST_RUNS];
 
376
    int i;
 
377
 
 
378
    ticks_start = UtilCpuGetTicks();
 
379
    for (i = 0; i < TEST_RUNS; i++) {
 
380
        ptr[i] = malloc(1024);
 
381
    }
 
382
    ticks_end = UtilCpuGetTicks();
 
383
    printf("malloc(1024) %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
384
 
 
385
    ticks_start = UtilCpuGetTicks();
 
386
    for (i = 0; i < TEST_RUNS; i++) {
 
387
        free(ptr[i]);
 
388
    }
 
389
    ticks_end = UtilCpuGetTicks();
 
390
    printf("free(1024) %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
391
 
 
392
    SCMutex m[TEST_RUNS];
 
393
 
 
394
    ticks_start = UtilCpuGetTicks();
 
395
    for (i = 0; i < TEST_RUNS; i++) {
 
396
        SCMutexInit(&m[i], NULL);
 
397
    }
 
398
    ticks_end = UtilCpuGetTicks();
 
399
    printf("SCMutexInit() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
400
 
 
401
    ticks_start = UtilCpuGetTicks();
 
402
    for (i = 0; i < TEST_RUNS; i++) {
 
403
        SCMutexLock(&m[i]);
 
404
    }
 
405
    ticks_end = UtilCpuGetTicks();
 
406
    printf("SCMutexLock() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
407
 
 
408
    ticks_start = UtilCpuGetTicks();
 
409
    for (i = 0; i < TEST_RUNS; i++) {
 
410
        SCMutexUnlock(&m[i]);
 
411
    }
 
412
    ticks_end = UtilCpuGetTicks();
 
413
    printf("SCMutexUnlock() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
414
 
 
415
    ticks_start = UtilCpuGetTicks();
 
416
    for (i = 0; i < TEST_RUNS; i++) {
 
417
        SCMutexDestroy(&m[i]);
 
418
    }
 
419
    ticks_end = UtilCpuGetTicks();
 
420
    printf("SCMutexDestroy() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
421
 
 
422
    SCSpinlock s[TEST_RUNS];
 
423
 
 
424
    ticks_start = UtilCpuGetTicks();
 
425
    for (i = 0; i < TEST_RUNS; i++) {
 
426
        SCSpinInit(&s[i], 0);
 
427
    }
 
428
    ticks_end = UtilCpuGetTicks();
 
429
    printf("SCSpinInit() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
430
 
 
431
    ticks_start = UtilCpuGetTicks();
 
432
    for (i = 0; i < TEST_RUNS; i++) {
 
433
        SCSpinLock(&s[i]);
 
434
    }
 
435
    ticks_end = UtilCpuGetTicks();
 
436
    printf("SCSpinLock() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
437
 
 
438
    ticks_start = UtilCpuGetTicks();
 
439
    for (i = 0; i < TEST_RUNS; i++) {
 
440
        SCSpinUnlock(&s[i]);
 
441
    }
 
442
    ticks_end = UtilCpuGetTicks();
 
443
    printf("SCSpinUnlock() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
444
 
 
445
    ticks_start = UtilCpuGetTicks();
 
446
    for (i = 0; i < TEST_RUNS; i++) {
 
447
        SCSpinDestroy(&s[i]);
 
448
    }
 
449
    ticks_end = UtilCpuGetTicks();
 
450
    printf("SCSpinDestroy() %"PRIu64"\n", (ticks_end - ticks_start)/TEST_RUNS);
 
451
 
 
452
    return 1;
 
453
}
 
454
 
358
455
#endif /* UNITTESTS */
359
456
 
360
457
void
362
459
{
363
460
#ifdef UNITTESTS
364
461
    UtRegisterTest("ProfilingTest01", ProfilingTest01, 1);
 
462
    UtRegisterTest("ProfilingGenericTicksTest01", ProfilingGenericTicksTest01, 1);
365
463
#endif /* UNITTESTS */
366
464
}
367
465