Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTCORBA / Activity / Periodic_Task.cpp
blob4bef00b9e64cd5f0fa705f801b73d09cbbf9a397
1 #include "Periodic_Task.h"
3 #include "ace/High_Res_Timer.h"
4 #include "tao/debug.h"
6 #include "Task_Stats.h"
8 Periodic_Task::Periodic_Task (void)
9 :barrier_ (0),
10 task_priority_ (0),
11 period_ (0),
12 exec_time_ (0),
13 phase_ (0),
14 iter_ (0),
15 load_ (0),
16 task_stats_ (0)
20 Periodic_Task::~Periodic_Task ()
22 delete task_stats_;
25 int
26 Periodic_Task::init_task (ACE_Arg_Shifter& arg_shifter)
28 const ACE_TCHAR *current_arg = 0;
30 while (arg_shifter.is_anything_left ())
32 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-JobName"))))
34 name_ = ACE_TEXT_ALWAYS_CHAR(current_arg);
35 arg_shifter.consume_arg ();
37 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Priority"))))
39 task_priority_ = ACE_OS::atoi (current_arg);
40 arg_shifter.consume_arg ();
42 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Period"))))
44 period_ = ACE_OS::atoi (current_arg);
45 arg_shifter.consume_arg ();
47 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ExecTime"))))
49 exec_time_ = ACE_OS::atoi (current_arg);
50 arg_shifter.consume_arg ();
52 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Phase"))))
54 phase_ = ACE_OS::atoi (current_arg);
55 arg_shifter.consume_arg ();
57 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Iter"))))
59 iter_ = ACE_OS::atoi (current_arg);
60 arg_shifter.consume_arg ();
62 // create the stat object.
63 ACE_NEW_RETURN (task_stats_, Task_Stats (iter_), -1);
65 if (task_stats_->init () == -1)
66 return -1;
68 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Load"))))
70 load_ = ACE_OS::atoi (current_arg);
71 arg_shifter.consume_arg ();
73 return 0;
75 else
77 ACE_DEBUG ((LM_DEBUG, "parse Task unknown option %s\n",
78 arg_shifter.get_current ()));
79 if (TAO_debug_level > 0)
80 ACE_DEBUG ((LM_DEBUG, "name %s, priority %d, period %duS, exec_time %duS, phase %duS, iter %d, load %d\n",
81 name_.c_str(), task_priority_, period_, exec_time_, phase_, iter_, load_));
82 break;
85 return 0;
88 const char*
89 Periodic_Task::job (void)
91 return name_.c_str ();
94 void
95 Periodic_Task::job (Job_ptr job)
97 job_ = Job::_duplicate (job);
100 void
101 Periodic_Task::dump_stats (ACE_TCHAR* msg)
103 ACE_TCHAR buf[BUFSIZ];
104 ACE_OS::sprintf (buf, ACE_TEXT("%s%s"), name_.c_str (), ACE_TEXT(".dat"));
106 ACE_TString fname (buf);
108 ACE_OS::sprintf (buf,ACE_TEXT("#%s #name %s, priority %d, period %ld, exec_time %ld, phase %ld, iter_ %d , load_ %d"),
109 msg, name_.c_str(), task_priority_, period_, exec_time_, phase_, iter_, load_);
111 task_stats_->dump_samples (fname.c_str (), buf,
112 ACE_High_Res_Timer::global_scale_factor ());