Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

prof.c 2.2 KiB

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