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);
39 Job_i::init (ACE_Arg_Shifter
& arg_shifter
)
41 // Read the name of the Job
42 job_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
43 arg_shifter
.consume_arg ();
45 // Read the name of the POA
46 POA_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
47 arg_shifter
.consume_arg ();
53 Job_i::work (CORBA::ULong work
,
54 CORBA::Short importance
)
56 static CORBA::ULong prime_number
= 9619;
58 if (TAO_debug_level
> 0)
60 "Job_i::work: %d units of work\n",
63 CORBA::Object_var object
=
64 this->dt_creator_
->orb ()->resolve_initial_references (
65 "RTScheduler_Current");
67 RTScheduling::Current_var current
=
68 RTScheduling::Current::_narrow (object
.in ());
69 RTScheduling::Current::IdType_var guid
= current
->id ();
72 ACE_OS::memcpy (&guid_
,
74 sizeof (guid
->length ()));
76 if (TAO_debug_level
> 0)
78 "%t Guid is %d, Importance is %d\n",
82 ACE_TCHAR msg
[BUFSIZ
];
85 ACE_SIZE_T_FORMAT_SPECIFIER
86 ACE_TEXT("\n"), guid_
);
88 dt_creator_
->log_msg (ACE_TEXT_ALWAYS_CHAR(msg
));
90 for (; work
!= 0; work
--)
92 // ACE_hrtime_t now = ACE_OS::gethrtime ();
94 ACE_Time_Value
*base_time
= dt_creator_
->base_time ();
98 ACE_Time_Value run_time
= ACE_OS::gettimeofday () - *(base_time
);
99 TASK_STATS::instance ()->sample (run_time
.sec (), guid_
);
101 ACE_Time_Value
count_down_time (1);
102 ACE_Countdown_Time
count_down (&count_down_time
);
104 while (count_down_time
> ACE_Time_Value::zero
)
106 ACE::is_prime (prime_number
,
109 count_down
.update ();
112 run_time
= ACE_OS::gettimeofday () - *(dt_creator_
->base_time ());
113 TASK_STATS::instance ()->sample (run_time
.sec (), guid_
);
115 CORBA::Policy_var sched_param
;
116 sched_param
= dt_creator_
->sched_param (importance
);
117 const char * name
= 0;
118 current
->update_scheduling_segment (name
,
125 Job_i::post_work (int /*guid*/,
139 dt_creator_
->job_ended ();
145 ACE_TCHAR fname
[BUFSIZ
];
146 ACE_OS::sprintf (fname
,
148 ACE_SIZE_T_FORMAT_SPECIFIER
152 if (TAO_debug_level
> 0)
153 ACE_DEBUG ((LM_DEBUG
,
157 ACE_TCHAR msg
[BUFSIZ
];
158 ACE_OS::sprintf (msg
,
159 ACE_TEXT("#Schedule Output for DT ")
160 ACE_SIZE_T_FORMAT_SPECIFIER
,
163 task_stats_
->dump_samples (fname
, msg
);