Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

99 linhas
2.2 KiB

  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