source: libcaca/trunk/caca/prof.c @ 4333

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This library is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13/*
14 *  This file contains profiling functions. They are not supposed to be
15 *  built with release versions.
16 */
17
18#include "config.h"
19
20#if !defined(__KERNEL__)
21#   include <stdio.h>
22#   include <stdarg.h>
23#   include <stdlib.h>
24#endif
25
26#include "caca.h"
27#include "caca_internals.h"
28
29#if defined PROF
30static struct caca_stat **stats = NULL;
31static int nstats = 0;
32
33void _caca_dump_stats(void)
34{
35    int i, j;
36
37    fprintf(stderr, "** libcaca profiling stats **\n");
38
39    for (i = 0; i < nstats; i++)
40    {
41         int64_t total = 0;
42
43         for (j = 0; j < STAT_VALUES; j++)
44             total += stats[i]->itable[j];
45
46         fprintf(stderr, " %s: last %i sliding mean %i smoothed mean %i\n",
47                 stats[i]->name, stats[i]->itable[0],
48                 (int)((total + STAT_VALUES / 2) / STAT_VALUES),
49                 (int)(stats[i]->imean / 64));
50    }
51
52    fprintf(stderr, "** %i counters dumped **\n", nstats);
53}
54
55void _caca_init_stat(struct caca_stat *s, const char *format, ...)
56{
57    int i;
58
59    s->name = malloc(128 * sizeof(char));
60    va_list args;
61    va_start(args, format);
62    vsnprintf(s->name, 128, format, args);
63    s->name[127] = '\0';
64    va_end(args);
65
66    nstats++;
67    stats = realloc(stats, nstats * sizeof(struct caca_stat *));
68    stats[nstats - 1] = s;
69
70    for (i = 0; i < STAT_VALUES; i++)
71        s->itable[i] = 0;
72    s->imean = 0;
73}
74
75void _caca_fini_stat(struct caca_stat *s)
76{
77    int i, j;
78
79    for (i = 0; i < nstats; i++)
80    {
81        if (stats[i] == s)
82        {
83            free(stats[i]->name);
84
85            for (j = i + 1; j < nstats; j++)
86                stats[j - 1] = stats[j];
87            nstats--;
88            stats = realloc(stats, nstats * sizeof(struct caca_stats *));
89
90            return;
91        }
92    }
93}
94
95#endif
96
Note: See TracBrowser for help on using the repository browser.