fxt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #ifdef STARPU_USE_FXT
  20. #include <common/fxt.h>
  21. #ifdef STARPU_HAVE_WINDOWS
  22. #include <windows.h>
  23. #endif
  24. #define PROF_BUFFER_SIZE (8*1024*1024)
  25. static char PROF_FILE_USER[128];
  26. static int fxt_started = 0;
  27. static int written = 0;
  28. static void profile_set_tracefile(char *fmt, ...)
  29. {
  30. va_list vl;
  31. char *user;
  32. va_start(vl, fmt);
  33. vsprintf(PROF_FILE_USER, fmt, vl);
  34. va_end(vl);
  35. user = getenv("USER");
  36. if (!user)
  37. user = "";
  38. int pid = getpid();
  39. char suffix[128];
  40. snprintf(suffix, 128, "prof_file_%s_%d", user, pid);
  41. strcat(PROF_FILE_USER, suffix);
  42. }
  43. void _starpu_start_fxt_profiling(void)
  44. {
  45. unsigned threadid;
  46. if (!fxt_started) {
  47. fxt_started = 1;
  48. char *fxt_prefix = getenv("STARPU_FXT_PREFIX");
  49. if (!fxt_prefix)
  50. fxt_prefix = "/tmp/";
  51. profile_set_tracefile(fxt_prefix);
  52. }
  53. threadid = syscall(SYS_gettid);
  54. atexit(_starpu_stop_fxt_profiling);
  55. if(fut_setup(PROF_BUFFER_SIZE, FUT_KEYMASKALL, threadid) < 0) {
  56. perror("fut_setup");
  57. STARPU_ABORT();
  58. }
  59. fut_keychange(FUT_ENABLE, FUT_KEYMASKALL, threadid);
  60. return;
  61. }
  62. void _starpu_stop_fxt_profiling(void)
  63. {
  64. if (!written)
  65. {
  66. #ifdef STARPU_VERBOSE
  67. char hostname[128];
  68. gethostname(hostname, 128);
  69. fprintf(stderr, "Writing FxT traces into file %s:%s\n", hostname, PROF_FILE_USER);
  70. #endif
  71. fut_endup(PROF_FILE_USER);
  72. int ret = fut_done();
  73. if (ret < 0)
  74. {
  75. /* Something went wrong with the FxT trace (eg. there
  76. * was too many events) */
  77. fprintf(stderr, "Warning: the FxT trace could not be generated properly\n");
  78. }
  79. written = 1;
  80. }
  81. }
  82. void _starpu_fxt_register_thread(unsigned cpuid)
  83. {
  84. FUT_DO_PROBE2(FUT_NEW_LWP_CODE, cpuid, syscall(SYS_gettid));
  85. }
  86. #endif
  87. void starpu_trace_user_event(unsigned long code __attribute__((unused)))
  88. {
  89. #ifdef STARPU_USE_FXT
  90. STARPU_TRACE_USER_EVENT(code);
  91. #endif
  92. }