Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2009-2012 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://www.wtfpl.net/ for more details.
  11. */
  12. /*
  13. * This file contains profiling functions. They are not supposed to be
  14. * built with release versions.
  15. */
  16. #include "config.h"
  17. #if !defined(__KERNEL__)
  18. # include <stdio.h>
  19. # include <stdarg.h>
  20. # include <stdlib.h>
  21. #endif
  22. #include "caca.h"
  23. #include "caca_internals.h"
  24. #if defined PROF
  25. static struct caca_stat **stats = NULL;
  26. static int nstats = 0;
  27. void _caca_dump_stats(void)
  28. {
  29. int i, j;
  30. fprintf(stderr, "** libcaca profiling stats **\n");
  31. for (i = 0; i < nstats; i++)
  32. {
  33. int64_t total = 0;
  34. for (j = 0; j < STAT_VALUES; j++)
  35. total += stats[i]->itable[j];
  36. fprintf(stderr, " %s: last %i sliding mean %i smoothed mean %i\n",
  37. stats[i]->name, stats[i]->itable[0],
  38. (int)((total + STAT_VALUES / 2) / STAT_VALUES),
  39. (int)(stats[i]->imean / 64));
  40. }
  41. fprintf(stderr, "** %i counters dumped **\n", nstats);
  42. }
  43. void _caca_init_stat(struct caca_stat *s, const char *format, ...)
  44. {
  45. int i;
  46. s->name = malloc(128 * sizeof(char));
  47. va_list args;
  48. va_start(args, format);
  49. vsnprintf(s->name, 128, format, args);
  50. s->name[127] = '\0';
  51. va_end(args);
  52. nstats++;
  53. stats = realloc(stats, nstats * sizeof(struct caca_stat *));
  54. stats[nstats - 1] = s;
  55. for (i = 0; i < STAT_VALUES; i++)
  56. s->itable[i] = 0;
  57. s->imean = 0;
  58. }
  59. void _caca_fini_stat(struct caca_stat *s)
  60. {
  61. int i, j;
  62. for (i = 0; i < nstats; i++)
  63. {
  64. if (stats[i] == s)
  65. {
  66. free(stats[i]->name);
  67. for (j = i + 1; j < nstats; j++)
  68. stats[j - 1] = stats[j];
  69. nstats--;
  70. stats = realloc(stats, nstats * sizeof(struct caca_stats *));
  71. return;
  72. }
  73. }
  74. }
  75. #endif