Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTScheduling / Task_Stats.cpp
blob053ffaf63a286233d0fb0def28467dd88ab9bd29
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 (void)
14 : base_time_(0),
15 end_time_ (0),
16 max_samples_ (0),
17 samples_count_ (0),
18 thr_run_time_ (0),
19 thr_count_ (0),
20 exec_time_min_ (0),
21 exec_time_min_at_ (0),
22 exec_time_max_ (0),
23 exec_time_max_at_(0),
24 sum_ (0),
25 sum2_ (0)
29 Task_Stats::~Task_Stats (void)
31 delete[] this->thr_run_time_;
32 delete[] this->thr_count_;
35 int
36 Task_Stats::init (size_t max_samples)
38 max_samples_ = max_samples;
39 ACE_NEW_RETURN (this->thr_run_time_, time_t[this->max_samples_], -1);
40 ACE_NEW_RETURN (this->thr_count_, int[this->max_samples_], -1);
41 return 0;
44 void
45 Task_Stats::base_time (ACE_hrtime_t time)
47 base_time_ = time;
50 void
51 Task_Stats::end_time (ACE_hrtime_t time)
53 end_time_ = time;
56 void
57 Task_Stats::dump_samples (const ACE_TCHAR *file_name, const ACE_TCHAR *msg)
59 // There's nothing to dump if this object was never initialized
60 if (this->thr_run_time_ == 0 || this->thr_count_ == 0)
61 return;
63 FILE* output_file = ACE_OS::fopen (file_name, "w");
65 if (output_file == 0)
67 ACE_ERROR ((LM_ERROR,
68 "%s cannot be opened\n",
69 file_name));
72 // first dump what the caller has to say.
73 ACE_OS::fprintf (output_file, "%s\n", ACE_TEXT_ALWAYS_CHAR (msg));
75 // next, compose and dump what we want to say.
76 ACE_UINT32 val_1;
77 int val_2;
78 ACE_UINT64 x;
80 x = this->thr_run_time_[0];// scale_factor;
81 val_1 = ACE_CU64_TO_CU32 (x);
83 ACE_OS::fprintf (output_file, "%u \t %d\n",val_1,thr_count_[0]);
85 // dump the samples recorded.
86 for (size_t i = 1; i != this->samples_count_; ++i)
88 x = this->thr_run_time_[i];
89 val_1 = ACE_CU64_TO_CU32 (x);
90 val_2 = this->thr_count_[i];
91 ACE_OS::fprintf (output_file, "%u \t %d\n",val_1,val_2);
94 ACE_OS::fclose (output_file);
96 ACE_DEBUG ((LM_DEBUG,
97 "Samples are ready to view\n"));
100 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, Task_Stats, TAO_SYNCH_MUTEX);