ser_profile.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifdef SER
  2. #ifdef DO_PROFILE
  3. #include <cds/ser_profile.h>
  4. #include "dprint.h"
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8. DEFINE_PROF_POINT(pa_handle_subscription)
  9. DEFINE_PROF_POINT(pa_timer_presentity)
  10. DEFINE_PROF_POINT(pa_timer_pdomain)
  11. DEFINE_PROF_POINT(pa_response_generation)
  12. DEFINE_PROF_POINT(rls_handle_subscription)
  13. DEFINE_PROF_POINT(rls_timer_cb)
  14. DEFINE_PROF_POINT(rls_is_simple_rls_target)
  15. DEFINE_PROF_POINT(rls_query_rls_sevices)
  16. DEFINE_PROF_POINT(rls_query_resource_list)
  17. DEFINE_PROF_POINT(rls_have_flat_list)
  18. DEFINE_PROF_POINT(tem_timer_cb)
  19. DEFINE_PROF_POINT(tem_add_event)
  20. DEFINE_PROF_POINT(tem_remove_event)
  21. DEFINE_PROF_POINT(tem_do_step)
  22. DEFINE_PROF_POINT(b2b_handle_notify)
  23. void prof_trace(FILE *f, int pid, const char *s, profile_data_t a)
  24. {
  25. fprintf(f, "%d\t%30s\t%d\t%u\n",
  26. pid, s, a.count, a.spent_time);
  27. if (a.start_count != a.stop_count)
  28. fprintf(f, "%s, %d start_count != stop_count (%d != %d)\n",
  29. s, pid, a.start_count, a.stop_count);
  30. }
  31. void prof_trace_nested(FILE *f, int pid, const char *s, profile_data_t a)
  32. {
  33. fprintf(f, "%d\t%29s*\t%d\t%u\n",
  34. pid, s, a.count, a.spent_time);
  35. if (a.start_count != a.stop_count)
  36. fprintf(f, "%s, %d start_count != stop_count (%d != %d)\n",
  37. s, pid, a.start_count, a.stop_count);
  38. }
  39. #define trace(f, p, name) prof_trace(f, p, #name , prof_point(name))
  40. #define trace_nested(f, p, name) prof_trace_nested(f, p, #name , prof_point(name))
  41. void trace_func()
  42. {
  43. pid_t p = getpid();
  44. FILE *f;
  45. f = fopen("/tmp/ser.profile", "at");
  46. if (!f) ERR("can't write into profile file\n");
  47. else {
  48. trace(f, p, pa_handle_subscription);
  49. trace(f, p, pa_timer_pdomain);
  50. trace_nested(f, p, pa_timer_presentity);
  51. trace_nested(f, p, pa_response_generation);
  52. trace(f, p, rls_handle_subscription);
  53. trace(f, p, rls_timer_cb);
  54. trace(f, p, rls_is_simple_rls_target);
  55. trace(f, p, rls_query_rls_sevices);
  56. trace(f, p, rls_query_resource_list);
  57. trace(f, p, rls_have_flat_list);
  58. /* trace_nested(f, p, tem_timer_cb); */
  59. trace(f, p, tem_add_event);
  60. trace(f, p, tem_remove_event);
  61. trace(f, p, tem_do_step);
  62. trace(f, p, b2b_handle_notify);
  63. fprintf(f, "%d\t%30s\t1\t%u\n", p, "all", get_prof_time());
  64. fclose(f);
  65. }
  66. }
  67. void ser_profile_init()
  68. {
  69. WARN("initializing profiler\n");
  70. start_profile(trace_func);
  71. }
  72. #endif /* DO_PROFILE */
  73. #endif /* SER */