2 #include "DT_Creator.h"
3 #include "Task_Stats.h"
7 #include "ace/Arg_Shifter.h"
8 #include "ace/High_Res_Timer.h"
9 #include "ace/OS_NS_sys_time.h"
10 #include "ace/Countdown_Time.h"
12 Job_i::Job_i (DT_Creator
* dt_creator
)
13 : dt_creator_ (dt_creator
),
16 // create the stat object.
17 ACE_NEW (task_stats_
, Task_Stats
);
18 task_stats_
->init (100);
40 Job_i::init (ACE_Arg_Shifter
& arg_shifter
)
42 // Read the name of the Job
43 job_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
44 arg_shifter
.consume_arg ();
46 // Read the name of the POA
47 POA_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
48 arg_shifter
.consume_arg ();
54 Job_i::work (CORBA::ULong work
,
55 CORBA::Short importance
)
57 static CORBA::ULong prime_number
= 9619;
59 if (TAO_debug_level
> 0)
61 "Job_i::work: %d units of work\n",
64 CORBA::Object_var object
=
65 this->dt_creator_
->orb ()->resolve_initial_references (
66 "RTScheduler_Current");
68 RTScheduling::Current_var current
=
69 RTScheduling::Current::_narrow (object
.in ());
70 RTScheduling::Current::IdType_var guid
= current
->id ();
73 ACE_OS::memcpy (&guid_
,
75 sizeof (guid
->length ()));
77 if (TAO_debug_level
> 0)
79 "%t Guid is %d, Importance is %d\n",
83 ACE_TCHAR msg
[BUFSIZ
];
86 ACE_SIZE_T_FORMAT_SPECIFIER
87 ACE_TEXT("\n"), guid_
);
89 dt_creator_
->log_msg (ACE_TEXT_ALWAYS_CHAR(msg
));
91 for (; work
!= 0; work
--)
93 // ACE_hrtime_t now = ACE_OS::gethrtime ();
95 ACE_Time_Value
*base_time
= dt_creator_
->base_time ();
99 ACE_Time_Value run_time
= ACE_OS::gettimeofday () - *(base_time
);
100 TASK_STATS::instance ()->sample (run_time
.sec (), guid_
);
102 ACE_Time_Value
count_down_time (1);
103 ACE_Countdown_Time
count_down (&count_down_time
);
105 while (count_down_time
> ACE_Time_Value::zero
)
107 ACE::is_prime (prime_number
,
110 count_down
.update ();
113 run_time
= ACE_OS::gettimeofday () - *(dt_creator_
->base_time ());
114 TASK_STATS::instance ()->sample (run_time
.sec (), guid_
);
116 CORBA::Policy_var sched_param
;
117 sched_param
= dt_creator_
->sched_param (importance
);
118 const char * name
= 0;
119 current
->update_scheduling_segment (name
,
126 Job_i::post_work (int /*guid*/,
138 Job_i::shutdown (void)
140 dt_creator_
->job_ended ();
144 Job_i::dump_stats (void)
146 ACE_TCHAR fname
[BUFSIZ
];
147 ACE_OS::sprintf (fname
,
149 ACE_SIZE_T_FORMAT_SPECIFIER
153 if (TAO_debug_level
> 0)
154 ACE_DEBUG ((LM_DEBUG
,
158 ACE_TCHAR msg
[BUFSIZ
];
159 ACE_OS::sprintf (msg
,
160 ACE_TEXT("#Schedule Output for DT ")
161 ACE_SIZE_T_FORMAT_SPECIFIER
,
164 task_stats_
->dump_samples (fname
, msg
);