Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Kokyu_dsrt_schedulers / Task_Stats.cpp
blobe266b41624ecef6ea80016f5525b4d25a0d8c29c
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_, ACE_UINT32[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 FILE* output_file = ACE_OS::fopen (file_name, "w");
61 if (output_file == 0)
63 ACE_ERROR ((LM_ERROR,
64 "%s cannot be opened\n",
65 file_name));
68 // first dump what the caller has to say.
69 ACE_OS::fprintf (output_file, "%s\n", ACE_TEXT_ALWAYS_CHAR (msg));
71 // next, compose and dump what we want to say.
72 ACE_UINT32 val_1;
73 int val_2;
74 ACE_UINT64 x;
76 // dump the samples recorded.
77 for (size_t i = 0; i < this->samples_count_; ++i)
79 x = this->thr_run_time_[i];
80 val_1 = ACE_CU64_TO_CU32 (x);
81 val_2 = this->thr_count_[i];
82 ACE_OS::fprintf (output_file, "%u \t %d\n",val_1,val_2);
85 ACE_OS::fclose (output_file);
87 ACE_DEBUG ((LM_DEBUG,
88 "Samples are ready to be viewed\n"));