perf_counters_01.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <assert.h>
  18. #include <string.h>
  19. static void print_scope(const enum starpu_perf_counter_scope scope)
  20. {
  21. int nb = starpu_perf_counter_nb(scope);
  22. int i;
  23. printf("scope %s\n", starpu_perf_counter_scope_id_to_name(scope));
  24. for (i=0; i<nb; i++)
  25. {
  26. const int id = starpu_perf_counter_nth_to_id(scope, i);
  27. const char *name = starpu_perf_counter_id_to_name(id);
  28. const char *help = starpu_perf_counter_get_help_string(id);
  29. int type_id = starpu_perf_counter_get_type_id(id);
  30. const char *type_name = starpu_perf_counter_type_id_to_name(type_id);
  31. printf("%d/%d - %s (0x%08x): [%s] / %s\n", i+1, nb, name, id, type_name, help);
  32. }
  33. }
  34. int main(int argc, char **argv)
  35. {
  36. int ret;
  37. ret = starpu_init(NULL);
  38. if (ret == -ENODEV)
  39. return 77;
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  41. {
  42. int id;
  43. id = starpu_perf_counter_scope_name_to_id("global");
  44. STARPU_ASSERT(id == starpu_perf_counter_scope_global);
  45. id = starpu_perf_counter_scope_name_to_id("per_worker");
  46. STARPU_ASSERT(id == starpu_perf_counter_scope_per_worker);
  47. id = starpu_perf_counter_scope_name_to_id("per_codelet");
  48. STARPU_ASSERT(id == starpu_perf_counter_scope_per_codelet);
  49. (void)id;
  50. }
  51. {
  52. const char *name;
  53. name = starpu_perf_counter_scope_id_to_name(starpu_perf_counter_scope_global);
  54. STARPU_ASSERT(strcmp(name, "global") == 0);
  55. name = starpu_perf_counter_scope_id_to_name(starpu_perf_counter_scope_per_worker);
  56. STARPU_ASSERT(strcmp(name, "per_worker") == 0);
  57. name = starpu_perf_counter_scope_id_to_name(starpu_perf_counter_scope_per_codelet);
  58. STARPU_ASSERT(strcmp(name, "per_codelet") == 0);
  59. (void)name;
  60. }
  61. {
  62. int id;
  63. id = starpu_perf_counter_type_name_to_id("int32");
  64. STARPU_ASSERT(id == starpu_perf_counter_type_int32);
  65. id = starpu_perf_counter_type_name_to_id("int64");
  66. STARPU_ASSERT(id == starpu_perf_counter_type_int64);
  67. id = starpu_perf_counter_type_name_to_id("float");
  68. STARPU_ASSERT(id == starpu_perf_counter_type_float);
  69. id = starpu_perf_counter_type_name_to_id("double");
  70. STARPU_ASSERT(id == starpu_perf_counter_type_double);
  71. (void)id;
  72. }
  73. {
  74. const char *name;
  75. name = starpu_perf_counter_type_id_to_name(starpu_perf_counter_type_int32);
  76. STARPU_ASSERT(strcmp(name, "int32") == 0);
  77. name = starpu_perf_counter_type_id_to_name(starpu_perf_counter_type_int64);
  78. STARPU_ASSERT(strcmp(name, "int64") == 0);
  79. name = starpu_perf_counter_type_id_to_name(starpu_perf_counter_type_float);
  80. STARPU_ASSERT(strcmp(name, "float") == 0);
  81. name = starpu_perf_counter_type_id_to_name(starpu_perf_counter_type_double);
  82. STARPU_ASSERT(strcmp(name, "double") == 0);
  83. (void)name;
  84. }
  85. printf("programmatically get counters per scope\n");
  86. print_scope(starpu_perf_counter_scope_global);
  87. print_scope(starpu_perf_counter_scope_per_worker);
  88. print_scope(starpu_perf_counter_scope_per_codelet);
  89. printf("\n");
  90. printf("list available counters per scope\n");
  91. starpu_perf_counter_list_avail(starpu_perf_counter_scope_global);
  92. starpu_perf_counter_list_avail(starpu_perf_counter_scope_per_worker);
  93. starpu_perf_counter_list_avail(starpu_perf_counter_scope_per_codelet);
  94. printf("\n");
  95. printf("list all available counters\n");
  96. starpu_perf_counter_list_all_avail();
  97. printf("\n");
  98. starpu_shutdown();
  99. return 0;
  100. }