perf_scheduler.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2020 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. * @file util/perf_scheduler.c
  19. * @brief measure performance of scheduler functions
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include <gauger.h>
  24. #define RUNS (1024 * 1024)
  25. static struct GNUNET_SCHEDULER_Task *task;
  26. static void
  27. run (void *cls)
  28. {
  29. uint64_t *count = cls;
  30. task = NULL;
  31. (*count)++;
  32. if (*count >= RUNS)
  33. {
  34. GNUNET_SCHEDULER_shutdown ();
  35. return;
  36. }
  37. task = GNUNET_SCHEDULER_add_now (&run,
  38. count);
  39. }
  40. static void
  41. do_shutdown (void *cls)
  42. {
  43. if (NULL != task)
  44. GNUNET_SCHEDULER_cancel (task);
  45. }
  46. static void
  47. first (void *cls)
  48. {
  49. uint64_t *count = cls;
  50. (*count)++;
  51. task = GNUNET_SCHEDULER_add_now (&run,
  52. count);
  53. GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
  54. NULL);
  55. }
  56. static uint64_t
  57. perf_scheduler ()
  58. {
  59. uint64_t count = 0;
  60. GNUNET_SCHEDULER_run (&first,
  61. &count);
  62. return count;
  63. }
  64. int
  65. main (int argc, char *argv[])
  66. {
  67. struct GNUNET_TIME_Absolute start;
  68. uint64_t tasks;
  69. start = GNUNET_TIME_absolute_get ();
  70. tasks = perf_scheduler ();
  71. printf ("Scheduler perf took %s\n",
  72. GNUNET_STRINGS_relative_time_to_string (
  73. GNUNET_TIME_absolute_get_duration (start),
  74. GNUNET_YES));
  75. GAUGER ("UTIL", "Scheduler",
  76. tasks / 1024 / (1
  77. + GNUNET_TIME_absolute_get_duration
  78. (start).rel_value_us / 1000LL), "tasks/ms");
  79. return 0;
  80. }
  81. /* end of perf_scheduler.c */