Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

107 řádky
2.7 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 mean %i sliding mean %i\n",
  39. stats[i]->name, stats[i]->itable[0],
  40. (int)((total + STAT_VALUES / 2) / STAT_VALUES),
  41. stats[i]->imean);
  42. /*fprintf(stderr, "%i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i\n",
  43. stats[i]->itable[0], stats[i]->itable[1], stats[i]->itable[2],
  44. stats[i]->itable[3], stats[i]->itable[4], stats[i]->itable[5],
  45. stats[i]->itable[6], stats[i]->itable[7], stats[i]->itable[8],
  46. stats[i]->itable[9], stats[i]->itable[10], stats[i]->itable[11],
  47. stats[i]->itable[12], stats[i]->itable[13], stats[i]->itable[14],
  48. stats[i]->itable[15], stats[i]->itable[16], stats[i]->itable[17],
  49. stats[i]->itable[18], stats[i]->itable[19]);*/
  50. }
  51. fprintf(stderr, "** %i counters dumped **\n", nstats);
  52. }
  53. void _caca_init_stat(struct caca_stat *s, const char *format, ...)
  54. {
  55. int i;
  56. s->name = malloc(128 * sizeof(char));
  57. va_list args;
  58. va_start(args, format);
  59. vsnprintf(s->name, 128, format, args);
  60. s->name[127] = '\0';
  61. va_end(args);
  62. nstats++;
  63. stats = realloc(stats, nstats * sizeof(struct caca_stat *));
  64. stats[nstats - 1] = s;
  65. for (i = 0; i < STAT_VALUES; i++)
  66. s->itable[i] = 0;
  67. s->imean = 0;
  68. }
  69. void _caca_fini_stat(struct caca_stat *s)
  70. {
  71. int i, j;
  72. for (i = 0; i < nstats; i++)
  73. {
  74. if (stats[i] == s)
  75. {
  76. free(stats[i]->name);
  77. for (j = i + 1; j < nstats; j++)
  78. stats[j - 1] = stats[j];
  79. nstats--;
  80. stats = realloc(stats, nstats * sizeof(struct caca_stats *));
  81. return;
  82. }
  83. }
  84. }
  85. #endif