fxt.c 2.4 KB

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