fxt.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <common/config.h>
  18. #ifdef STARPU_USE_FXT
  19. #include <common/fxt.h>
  20. #define PROF_BUFFER_SIZE (8*1024*1024)
  21. static char PROF_FILE_USER[128];
  22. static int fxt_started = 0;
  23. static int written = 0;
  24. static void profile_set_tracefile(char *fmt, ...)
  25. {
  26. va_list vl;
  27. char *user;
  28. va_start(vl, fmt);
  29. vsprintf(PROF_FILE_USER, fmt, vl);
  30. va_end(vl);
  31. user = getenv("USER");
  32. if (!user)
  33. user = "";
  34. int pid = getpid();
  35. char suffix[128];
  36. snprintf(suffix, 128, "prof_file_%s_%d", user, pid);
  37. strcat(PROF_FILE_USER, suffix);
  38. }
  39. void _starpu_start_fxt_profiling(void)
  40. {
  41. unsigned threadid;
  42. if (!fxt_started) {
  43. fxt_started = 1;
  44. char *fxt_prefix = getenv("STARPU_FXT_PREFIX");
  45. if (!fxt_prefix)
  46. fxt_prefix = "/tmp/";
  47. profile_set_tracefile(fxt_prefix);
  48. }
  49. threadid = syscall(SYS_gettid);
  50. atexit(_starpu_stop_fxt_profiling);
  51. if(fut_setup(PROF_BUFFER_SIZE, FUT_KEYMASKALL, threadid) < 0) {
  52. perror("fut_setup");
  53. STARPU_ABORT();
  54. }
  55. fut_keychange(FUT_ENABLE, FUT_KEYMASKALL, threadid);
  56. return;
  57. }
  58. void _starpu_stop_fxt_profiling(void)
  59. {
  60. if (!written)
  61. {
  62. #ifdef STARPU_VERBOSE
  63. char hostname[128];
  64. gethostname(hostname, 128);
  65. fprintf(stderr, "Writing FxT traces into file %s:%s\n", hostname, PROF_FILE_USER);
  66. #endif
  67. fut_endup(PROF_FILE_USER);
  68. int ret = fut_done();
  69. if (ret < 0)
  70. {
  71. /* Something went wrong with the FxT trace (eg. there
  72. * was too many events) */
  73. fprintf(stderr, "Warning: the FxT trace could not be generated properly\n");
  74. }
  75. written = 1;
  76. }
  77. }
  78. void _starpu_fxt_register_thread(unsigned cpuid)
  79. {
  80. FUT_DO_PROBE2(FUT_NEW_LWP_CODE, cpuid, syscall(SYS_gettid));
  81. }
  82. #endif
  83. void starpu_trace_user_event(unsigned code __attribute__((unused)))
  84. {
  85. #ifdef STARPU_USE_FXT
  86. STARPU_TRACE_USER_EVENT(code);
  87. #endif
  88. }