Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTScheduling / Thread_Task.cpp
blob1047365b4e00676b5ae2864c6e417f69c668506d
1 #include "Thread_Task.h"
2 #include "DT_Creator.h"
3 #include "Task_Stats.h"
5 #include "tao/ORB_Core.h"
7 #include "ace/High_Res_Timer.h"
8 #include "ace/Atomic_Op.h"
10 Thread_Task::Thread_Task (void)
11 : start_time_ (0),
12 load_ (0),
13 iter_ (0),
14 count_ (0),
15 importance_ (0),
16 dt_creator_ (0),
17 base_time_ (0),
18 dist_ (0),
19 job_name_ (),
20 task_stats_ (0)
24 int
25 Thread_Task::svc (void)
27 try
29 if (TAO_debug_level > 0)
31 ACE_DEBUG ((LM_DEBUG,
32 "Thread_Task::svc %d\n",
33 importance_));
36 const char * name = 0;
37 CORBA::Policy_var implicit_sched_param = CORBA::Policy::_duplicate (sched_param_.in ());;
38 this->current_->begin_scheduling_segment (name,
39 sched_param_.in (),
40 implicit_sched_param.in ());
42 RTScheduling::Current::IdType_var guid = this->current_->id ();
43 ACE_OS::memcpy (&count_,
44 guid->get_buffer (),
45 guid->length ());
47 ACE_TCHAR msg [BUFSIZ];
48 ACE_OS::sprintf (msg,
49 ACE_TEXT("Thread_Task::svc Imp=%d Guid=")
50 ACE_SIZE_T_FORMAT_SPECIFIER
51 ACE_TEXT("\n"),
52 importance_,
53 count_);
55 dt_creator_->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));
57 this->perform_task ();
59 this->current_->end_scheduling_segment (name);
61 dt_creator_->dt_ended () ;
63 catch (const CORBA::THREAD_CANCELLED &)
65 // Threads can be cancelled.
67 catch (const CORBA::Exception& ex)
69 ex._tao_print_exception ("Caught exception:");
71 return 0;
74 int
75 Thread_Task::importance (void)
77 return this->importance_;
80 time_t
81 Thread_Task::start_time (void)
83 return this->start_time_;
86 int
87 Thread_Task::perform_task (void)
89 return 0;
93 const char*
94 Thread_Task::job (void)
96 return job_name_.in ();
99 void
100 Thread_Task::job (Job_ptr job)
102 job_ = Job::_duplicate (job);
106 Thread_Task::dist (void)
108 return this->dist_;
111 void
112 Thread_Task::dump_stats (void)
114 ACE_TCHAR fname [BUFSIZ];
115 ACE_OS::sprintf (fname,
116 ACE_TEXT("DT_")
117 ACE_SIZE_T_FORMAT_SPECIFIER
118 ACE_TEXT(".dat"),
119 count_);
121 if (TAO_debug_level > 0)
122 ACE_DEBUG ((LM_DEBUG,
123 "File name %s\n",
124 fname));
126 ACE_TCHAR msg [BUFSIZ];
127 ACE_OS::sprintf (msg,
128 ACE_TEXT("#Schedule Output for DT ")
129 ACE_SIZE_T_FORMAT_SPECIFIER,
130 count_);
132 task_stats_->dump_samples (fname, msg);