1 #include "Task_Stats.h"
2 #include "ace/Log_Msg.h"
4 #if !defined (__ACE_INLINE__)
5 #include "Task_Stats.inl"
6 #endif /* __ACE_INLINE__ */
8 Base_Time::Base_Time (void)
10 base_time_
= ACE_OS::gethrtime ();
13 Task_Stats::Task_Stats (size_t max_samples
)
16 max_samples_ (max_samples
),
21 exec_time_min_at_ (0),
29 Task_Stats::~Task_Stats (void)
31 delete[] this->time_inv_
;
32 delete[] this->time_exec_
;
36 Task_Stats::init (void)
38 ACE_NEW_RETURN (this->time_inv_
, ACE_UINT64
[this->max_samples_
], -1);
39 ACE_NEW_RETURN (this->time_exec_
, ACE_UINT64
[this->max_samples_
], -1);
44 Task_Stats::base_time (ACE_hrtime_t time
)
50 Task_Stats::end_time (ACE_hrtime_t time
)
56 Task_Stats::dump_samples (
57 const ACE_TCHAR
*file_name
,
59 ACE_High_Res_Timer::global_scale_factor_type scale_factor
)
61 FILE* output_file
= ACE_OS::fopen (file_name
, "w");
63 // first dump what the caller has to say.
64 ACE_OS::fprintf (output_file
, "%s\n", ACE_TEXT_ALWAYS_CHAR (msg
));
66 // next, compose and dump what we want to say.
70 ACE_TCHAR out_msg
[BUFSIZ
];
72 ACE_hrtime_t elapsed_microseconds
= (end_time_
- base_time_
) / scale_factor
;
73 double elapsed_seconds
=
74 ACE_CU64_TO_CU32(elapsed_microseconds
) / 1000000.0;
76 double(samples_count_
) / elapsed_seconds
;
78 ACE_OS::sprintf (out_msg
, ACE_TEXT("#Throughtput: %f\n"), throughput
);
79 ACE_OS::fprintf (output_file
, ACE_TEXT("%s\n"),out_msg
);
81 // dump latency stats.
82 this->dump_latency_stats (out_msg
, scale_factor
);
83 ACE_OS::fprintf (output_file
, "%s\n", ACE_TEXT_ALWAYS_CHAR (out_msg
));
84 ACE_OS::fprintf (output_file
, "#Invocation time \t Execution time\n");
86 // dump the samples recorded.
87 for (size_t i
= 0; i
!= this->samples_count_
; ++i
)
89 ACE_UINT64 x
= this->time_inv_
[i
] / scale_factor
;
90 ACE_UINT32 val_1
= ACE_CU64_TO_CU32 (x
);
92 ACE_UINT64 y
= this->time_exec_
[i
] / scale_factor
;
93 ACE_UINT32 val_2
= ACE_CU64_TO_CU32 (y
);
95 ACE_OS::fprintf (output_file
, "%u \t %u\n",val_1
, val_2
);
98 ACE_OS::fclose (output_file
);
102 Task_Stats::dump_latency_stats (
104 ACE_High_Res_Timer::global_scale_factor_type sf
)
106 if (this->samples_count_
== 0u)
108 ACE_OS::sprintf (out_msg
,
109 ACE_TEXT ("# no data collected\n"));
113 ACE_UINT64 avg
= this->sum_
/ this->samples_count_
;
115 this->sum2_
/ this->samples_count_
- avg
* avg
;
117 ACE_UINT64 l_min_
= this->exec_time_min_
/ sf
;
118 ACE_UINT32 l_min
= ACE_CU64_TO_CU32 (l_min_
);
120 ACE_UINT64 l_max_
= this->exec_time_max_
/ sf
;
121 ACE_UINT32 l_max
= ACE_CU64_TO_CU32 (l_max_
);
123 ACE_UINT32 l_avg
= ACE_CU64_TO_CU32(avg
/ sf
);
124 ACE_UINT32 l_dev
= ACE_CU64_TO_CU32(dev
/ (sf
* sf
));
126 ACE_UINT64 tmin_
= this->time_inv_
[0] / sf
;
127 ACE_UINT32 tmin
= ACE_CU64_TO_CU32 (tmin_
);
129 ACE_UINT64 tmax_
= this->time_inv_
[samples_count_
-1] / sf
;
130 ACE_UINT32 tmax
= ACE_CU64_TO_CU32 (tmax_
);
132 ACE_OS::sprintf(out_msg
,
133 ACE_TEXT ("#latency : %u[%d]/%u/%u[%d]/%u (min/avg/max/var^2)\n #first invocation time = %u, last invocation time = %u\n"),
134 l_min
, this->exec_time_min_at_
,
136 l_max
, this->exec_time_max_at_
,
141 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton
, Base_Time
, TAO_SYNCH_MUTEX
);