track-usage.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2004-2021 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #include "mupdf/fitz.h"
  23. #ifdef TRACK_USAGE
  24. static track_usage_data_t *usage_head = NULL;
  25. static void dump_usage(void)
  26. {
  27. track_usage_data_t *u = usage_head;
  28. while (u)
  29. {
  30. fprintf(stderr, "USAGE: %s (%s:%d) %d calls\n",
  31. u->desc, u->function, u->line, u->count);
  32. u = u->next;
  33. }
  34. }
  35. void track_usage(track_usage_data_t *data, const char *function, int line, const char *desc)
  36. {
  37. int c = data->count++;
  38. if (c == 0)
  39. {
  40. data->function = function;
  41. data->line = line;
  42. data->desc = desc;
  43. if (usage_head == NULL)
  44. atexit(dump_usage);
  45. data->next = usage_head;
  46. usage_head = data;
  47. }
  48. }
  49. #endif