1 /* ///////////////////////////////////////////////////////////////////////
2 * File: threadtimes_counter.h
7 * Brief: The threadtimes_counter class - precision: ms
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WINDOWS_THREAD_TIMES_COUNTER_H
13 #define EXTL_PLATFORM_WINDOWS_THREAD_TIMES_COUNTER_H
15 /*!\file threadtimes_counter.h
16 * \brief threadtimes_counter class - precision: ms
19 # error threadtimes_counter.h need be supported by c++.
22 /* ///////////////////////////////////////////////////////////////////////
27 /* ///////////////////////////////////////////////////////////////////////
28 * ::extl::platform::windows namespace
30 EXTL_WINDOWS_BEGIN_WHOLE_NAMESPACE
32 /*!\brief threadtimes_counter class
34 * \ingroup extl_group_counter
36 class threadtimes_counter
38 /// \name Constructors
41 threadtimes_counter();
47 typedef threadtimes_counter class_type
;
48 typedef HANDLE handle_type
;
49 #ifdef EXTL_64BIT_INT_SUPPORT
50 typedef e_uint64_t interval_type
;
51 typedef e_uint64_t size_type
;
53 typedef e_uint32_t interval_type
;
54 typedef e_uint32_t size_type
;
69 inline interval_type
count() const;
70 inline interval_type
s() const;
71 inline interval_type
ms() const;
72 inline interval_type
us() const;
75 inline interval_type
kernel_count() const;
76 inline interval_type
kernel_s() const;
77 inline interval_type
kernel_ms() const;
78 inline interval_type
kernel_us() const;
81 inline interval_type
user_count() const;
82 inline interval_type
user_s() const;
83 inline interval_type
user_ms() const;
84 inline interval_type
user_us() const;
88 inline handle_type
thread_handle() const;
93 size_type m_kernel_start
;
94 size_type m_kernel_stop
;
96 size_type m_user_start
;
97 size_type m_user_stop
;
99 handle_type m_ht
; //!< Thread Handle
103 /* ///////////////////////////////////////////////////////////////////////
104 * Class implementation
106 inline threadtimes_counter::threadtimes_counter()
111 , m_ht(thread_handle())
114 inline threadtimes_counter::
115 handle_type
threadtimes_counter::thread_handle() const
117 handle_type ht
= ::GetCurrentThread();
118 EXTL_ASSERT(ht
!= NULL
);
121 inline void threadtimes_counter::start()
123 FILETIME creation_time
;
126 ::GetThreadTimes(m_ht
, &creation_time
, &exit_time
, \
127 reinterpret_cast<LPFILETIME
>(&m_kernel_start
), reinterpret_cast<LPFILETIME
>(&m_user_start
));
129 inline void threadtimes_counter::stop()
131 FILETIME creation_time
;
134 ::GetThreadTimes(m_ht
, &creation_time
, &exit_time
, \
135 reinterpret_cast<LPFILETIME
>(&m_kernel_stop
), reinterpret_cast<LPFILETIME
>(&m_user_stop
));
138 inline threadtimes_counter::interval_type
threadtimes_counter::kernel_count() const
140 EXTL_ASSERT(m_kernel_stop
>= m_kernel_start
);
141 return static_cast<interval_type
>(m_kernel_stop
- m_kernel_start
);
143 inline threadtimes_counter::interval_type
threadtimes_counter::kernel_s() const
145 return kernel_count() / interval_type(10000000);
147 inline threadtimes_counter::interval_type
threadtimes_counter::kernel_ms() const
149 return kernel_count() / interval_type(10000);
151 inline threadtimes_counter::interval_type
threadtimes_counter::kernel_us() const
153 return kernel_count() / interval_type(10);
156 inline threadtimes_counter::interval_type
threadtimes_counter::user_count() const
158 EXTL_ASSERT(m_user_stop
>= m_user_start
);
159 return static_cast<interval_type
>(m_user_stop
- m_user_start
);
161 inline threadtimes_counter::interval_type
threadtimes_counter::user_s() const
163 return user_count() / interval_type(10000000);
165 inline threadtimes_counter::interval_type
threadtimes_counter::user_ms() const
167 return user_count() / interval_type(10000);
169 inline threadtimes_counter::interval_type
threadtimes_counter::user_us() const
171 return user_count() / interval_type(10);
174 inline threadtimes_counter::interval_type
threadtimes_counter::count() const
176 return kernel_count() + user_count();
178 inline threadtimes_counter::interval_type
threadtimes_counter::s() const
180 return count() / interval_type(10000000);
182 inline threadtimes_counter::interval_type
threadtimes_counter::ms() const
184 return count() / interval_type(10000);
186 inline threadtimes_counter::interval_type
threadtimes_counter::us() const
188 return count() / interval_type(10);
191 /* ///////////////////////////////////////////////////////////////////////
192 * ::extl::platform::windows namespace
194 EXTL_WINDOWS_END_WHOLE_NAMESPACE
196 /* //////////////////////////////////////////////////////////////////// */
197 #endif /* EXTL_PLATFORM_WINDOWS_THREAD_TIMES_COUNTER_H */
198 /* //////////////////////////////////////////////////////////////////// */