Changeset 4094 for libcaca/trunk


Ignore:
Timestamp:
Dec 6, 2009, 10:21:40 PM (10 years ago)
Author:
Sam Hocevar
Message:

Gather profiling information in caca_refresh_display() and caca_get_event().

Location:
libcaca/trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/bootstrap

    r3643 r4094  
    1313#
    1414# The latest version of this script can be found at the following place:
    15 #   http://sam.zoy.org/autotools/
     15#   http://caca.zoy.org/wiki/build
    1616
    1717# Die if an error occurs
  • libcaca/trunk/caca/Makefile.am

    r4045 r4094  
    4646        event.c \
    4747        time.c \
     48        prof.c \
    4849        $(codec_source) \
    4950        $(driver_source) \
  • libcaca/trunk/caca/caca.c

    r3570 r4094  
    11/*
    22 *  libcaca       Colour ASCII-Art library
    3  *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
    44 *                All Rights Reserved
    55 *
     
    328328    dp->timer.last_sec = 0;
    329329    dp->timer.last_usec = 0;
     330#if defined PROF
     331    _caca_init_stat(&dp->display_stat, "dp[%p] disp_sys time", dp);
     332    _caca_init_stat(&dp->wait_stat, "dp[%p] disp_wait time", dp);
     333    _caca_init_stat(&dp->ev_sys_stat, "dp[%p] ev_sys time", dp);
     334    _caca_init_stat(&dp->ev_wait_stat, "dp[%p] ev_wait time", dp);
     335#endif
    330336    dp->lastticks = 0;
    331337
     
    347353    if(dp->plugin)
    348354        dlclose(dp->plugin);
     355#endif
     356#if defined PROF
     357    _caca_fini_stat(&dp->display_stat);
     358    _caca_fini_stat(&dp->wait_stat);
     359    _caca_fini_stat(&dp->ev_wait_stat);
     360    _caca_fini_stat(&dp->ev_sys_stat);
    349361#endif
    350362
  • libcaca/trunk/caca/caca_internals.h

    r3905 r4094  
    11/*
    22 *  libcaca       Colour ASCII-Art library
    3  *  Copyright (c) 2002-2006 Sam Hocevar <sam@hocevar.net>
     3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
    44 *                All Rights Reserved
    55 *
     
    2525
    2626#if !defined(_DOXYGEN_SKIP_ME)
     27#   define STAT_VALUES 20
    2728#   define EVENTBUF_LEN 10
    2829#   define MAX_DIRTY_COUNT 8
     
    143144{
    144145    int last_sec, last_usec;
     146};
     147
     148/* Statistic structure for profiling */
     149struct caca_stat
     150{
     151    char *name;
     152    int imean, itable[STAT_VALUES];
    145153};
    146154
     
    205213    int delay, rendertime;
    206214    caca_timer_t timer;
     215#if defined PROF
     216    struct caca_stat display_stat, wait_stat;
     217    struct caca_stat ev_sys_stat, ev_wait_stat;
     218#endif
    207219    int lastticks;
    208220
     
    250262extern void _caca_set_term_title(char const *);
    251263
     264/* Profiling functions */
     265#if defined PROF
     266extern void _caca_dump_stats(void);
     267extern void _caca_init_stat(struct caca_stat *, char const *, ...);
     268extern void _caca_fini_stat(struct caca_stat *);
     269#endif
     270
    252271#endif /* __CACA_INTERNALS_H__ */
  • libcaca/trunk/caca/caca_prof.h

    r3905 r4094  
    2121#if defined PROF && !defined __KERNEL__
    2222#   define PROFILING_VARS
     23
     24#   define STAT_IADD(s, n) \
     25      do \
     26      { \
     27        struct caca_stat *ss = s; \
     28        int ii, nn = n; \
     29        for (ii = STAT_VALUES - 1; ii > 0; ii--) \
     30            ss->itable[ii] = ss->itable[ii - 1]; \
     31        ss->itable[0] = nn; \
     32        ss->imean = ((int64_t)ss->imean * 15 + nn) / 16; \
     33      } \
     34      while(0)
     35
    2336#   define START_PROF(obj, fn)
    2437#   define STOP_PROF(obj, fn)
     
    2639#else
    2740#   define PROFILING_VARS
     41#   define STAT_IADD(s) do { } while(0)
    2842#   define START_PROF(obj, fn) do { } while(0)
    2943#   define STOP_PROF(obj, fn) do { } while(0)
  • libcaca/trunk/caca/event.c

    r3619 r4094  
    11/*
    22 *  libcaca       Colour ASCII-Art library
    3  *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
    44 *                All Rights Reserved
    55 *
     
    6868    caca_privevent_t privevent;
    6969    caca_timer_t timer = {0, 0};
    70     int usec = 0;
     70#if defined PROF
     71    caca_timer_t proftimer = {0, 0};
     72    int profsys = 0, profwait = 0;
     73#endif
     74    int ret = 0, usec = 0;
     75
     76#if defined PROF
     77    _caca_getticks(&proftimer);
     78#endif
    7179
    7280    if(!event_mask)
    73         return 0;
     81        goto end;
    7482
    7583    if(timeout > 0)
     
    7886    for( ; ; )
    7987    {
    80         int ret = _get_next_event(dp, &privevent);
     88#if defined PROF
     89        profwait += _caca_getticks(&proftimer);
     90#endif
     91        ret = _get_next_event(dp, &privevent);
     92#if defined PROF
     93        profsys += _caca_getticks(&proftimer);
     94#endif
    8195
    8296        /* If we got the event we wanted, return */
     
    8599            if(ev)
    86100                memcpy(ev, &privevent, sizeof(privevent));
    87             return ret;
     101            goto end;
    88102        }
    89103
     
    101115            if(ev)
    102116                memcpy(ev, &privevent, sizeof(privevent));
    103             return 0;
     117            ret = 0;
     118            goto end;
    104119        }
    105120
    106121        /* Otherwise sleep a bit. Our granularity is far too high for values
    107122         * below 10000 microseconds so we cheat a bit. */
    108         if(usec > 10000)
    109             _caca_sleep(10000);
    110         else
    111             _caca_sleep(1000);
     123        _caca_sleep(usec > 10000 ? 10000 : 1000);
    112124
    113125        usec += _caca_getticks(&timer);
    114126    }
     127
     128end:
     129#if defined PROF
     130    profwait += _caca_getticks(&proftimer);
     131    STAT_IADD(&dp->ev_sys_stat, profsys);
     132    STAT_IADD(&dp->ev_wait_stat, profwait);
     133#endif
     134
     135    return ret;
    115136}
    116137
  • libcaca/trunk/caca/graphics.c

    r3571 r4094  
    148148int caca_refresh_display(caca_display_t *dp)
    149149{
     150#if defined PROF
     151    caca_timer_t proftimer = { 0, 0 };
     152#endif
    150153#if !defined(_DOXYGEN_SKIP_ME)
    151 #define IDLE_USEC 5000
     154#   define IDLE_USEC 5000
    152155#endif
    153156    int ticks = dp->lastticks + _caca_getticks(&dp->timer);
    154157
     158#if defined PROF
     159    _caca_getticks(&proftimer);
     160#endif
    155161    dp->drv.display(dp);
     162#if defined PROF
     163    STAT_IADD(&dp->display_stat, _caca_getticks(&proftimer));
     164#endif
    156165
    157166    /* Invalidate the dirty rectangle */
     
    165174    }
    166175
     176#if defined PROF
     177    _caca_getticks(&proftimer);
     178#endif
    167179    /* Wait until dp->delay + time of last call */
    168180    ticks += _caca_getticks(&dp->timer);
     
    173185        _caca_sleep(IDLE_USEC);
    174186    }
     187#if defined PROF
     188    STAT_IADD(&dp->wait_stat, _caca_getticks(&proftimer));
     189#endif
    175190
    176191    /* Update the render time */
     
    183198        dp->lastticks = 0;
    184199
     200#if defined PROF
     201    _caca_dump_stats();
     202#endif
     203
    185204    return 0;
    186205}
  • libcaca/trunk/caca/libcaca.vcproj

    r3905 r4094  
    486486                </File>
    487487                <File
     488                        RelativePath="prof.c"
     489                        >
     490                </File>
     491                <File
    488492                        RelativePath="string.c"
    489493                        >
  • libcaca/trunk/configure.ac

    r4044 r4094  
    9191AC_ARG_ENABLE(debug,
    9292  [  --enable-debug          build debug versions of the library (default no)])
    93 AC_ARG_ENABLE(prof,
    94   [  --enable-prof           activate built-in profiling (default no)])
     93AC_ARG_ENABLE(profiling,
     94  [  --enable-profiling      activate built-in profiling (default no)])
    9595AC_ARG_ENABLE(plugins,
    9696  [  --enable-plugins        make X11 and GL drivers plugins (default disabled)])
     
    322322fi
    323323
    324 if test "${enable_prof}" = "yes"; then
     324if test "${enable_profiling}" = "yes"; then
    325325  AC_DEFINE(PROF, 1, Define to 1 to activate profiling)
    326326fi
Note: See TracChangeset for help on using the changeset viewer.