1 #include "Periodic_Task.h"
3 #include "ace/High_Res_Timer.h"
6 #include "Task_Stats.h"
8 Periodic_Task::Periodic_Task (void)
20 Periodic_Task::~Periodic_Task ()
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)
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 ();
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_
));
89 Periodic_Task::job (void)
91 return name_
.c_str ();
95 Periodic_Task::job (Job_ptr job
)
97 job_
= Job::_duplicate (job
);
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 ());