remove \r
[extl.git] / extl / platform_ / windows / counter / threadtimes_counter.h
blobecc2634ae194135444c7268eae65f469ecd795e2
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: threadtimes_counter.h
4 * Created: 08.02.17
5 * Updated: 08.11.13
7 * Brief: The threadtimes_counter class - precision: ms
9 * [<Home>]
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
18 #ifndef __cplusplus
19 # error threadtimes_counter.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "prefix.h"
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
39 /// @{
40 public :
41 threadtimes_counter();
42 /// @}
44 /// \name Types
45 /// @{
46 private:
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;
52 #else
53 typedef e_uint32_t interval_type;
54 typedef e_uint32_t size_type;
55 #endif
56 /// @}
58 /// \name Operations
59 /// @{
60 public:
61 inline void start();
62 inline void stop();
63 /// @}
65 /// \name Attributes
66 /// @{
67 public:
68 // Kernel + User
69 inline interval_type count() const;
70 inline interval_type s() const;
71 inline interval_type ms() const;
72 inline interval_type us() const;
74 // Kernel
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;
80 // User
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;
85 /// @}
87 private:
88 inline handle_type thread_handle() const;
90 /// \name Members
91 /// @{
92 private:
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
100 /// @}
103 /* ///////////////////////////////////////////////////////////////////////
104 * Class implementation
106 inline threadtimes_counter::threadtimes_counter()
107 : m_kernel_start(0)
108 , m_kernel_stop(0)
109 , m_user_start(0)
110 , m_user_stop(0)
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);
119 return ht;
121 inline void threadtimes_counter::start()
123 FILETIME creation_time;
124 FILETIME exit_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;
132 FILETIME exit_time;
134 ::GetThreadTimes(m_ht, &creation_time, &exit_time, \
135 reinterpret_cast<LPFILETIME>(&m_kernel_stop), reinterpret_cast<LPFILETIME>(&m_user_stop));
137 /* Kernel */
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);
155 /* User */
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);
173 /* Kernel + User */
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 /* //////////////////////////////////////////////////////////////////// */