TNB Library
TnbPerformanceCount.h
[詳解]
1#pragma once
11#include "TnbDef.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
37{
38public:
39
45 {
46 LARGE_INTEGER li;
47 m_isValid = !! ::QueryPerformanceFrequency(&m_freq);
48 m_isValid &= !! ::QueryPerformanceCounter(&m_count);
49 ::QueryPerformanceCounter(&li);
50 m_apiCount = li.QuadPart - m_count.QuadPart;
51 ASSERT0( m_isValid, "CPerformanceCount", "PerformanceCount が使用できません." );
52 //TRACE2("PerformanceCount Resolution= %d(ns), %d\n", GetResolutionNanoCount(), static_cast<DWORD>(m_apiCount) );
53 ::QueryPerformanceCounter(&m_count);
54 m_count.QuadPart += m_apiCount;
55 }
56
62 bool IsValid(void) const
63 {
64 return m_isValid;
65 }
66
71 void Reset(void)
72 {
73 ::QueryPerformanceFrequency(&m_freq);
74 ::QueryPerformanceCounter(&m_count);
75 m_count.QuadPart += m_apiCount;
76 }
77
83 LONGLONG GetPassedCount(void) const
84 {
85 LARGE_INTEGER c;
86 ::QueryPerformanceCounter(&c);
87 LONGLONG d = c.QuadPart - m_count.QuadPart;
88 return (d * 1000 * 1000 / m_freq.QuadPart);
89 }
90
96 LONGLONG GetPassedNanoCount(void) const
97 {
98 LARGE_INTEGER c;
99 ::QueryPerformanceCounter(&c);
100 LONGLONG d = c.QuadPart - m_count.QuadPart;
101 return (d * 1000 * 1000 * 1000 / m_freq.QuadPart);
102 }
103
110 DWORD GetResolutionNanoCount(void) const
111 {
112 return static_cast<DWORD>(1000 * 1000 * 1000 / m_freq.QuadPart);
113 }
114
122 bool IsPassed(DWORD dwTime) const
123 {
124 return GetPassedCount() >= dwTime;
125 }
126
135 bool IsPassedAndReset(DWORD dwTime)
136 {
137 bool r = IsPassed(dwTime);
138 if ( r ){ Reset(); }
139 return r;
140 }
141
147 void OutputDebugPassedCount(void) const
148 {
149 TRACE1( " passed count = %.6f(ms)\n", static_cast<double>(GetPassedNanoCount() / 1000000.0) );
150 }
151
152private:
153 LARGE_INTEGER m_count;
154 LARGE_INTEGER m_freq;
155 LONGLONG m_apiCount;
156 bool m_isValid;
157};
158
159
160
161};//TNB
TNBライブラリの定義ヘッダ
経過時間管理(高分解能)
bool IsValid(void) const
[確認] 有効?
CPerformanceCount(void)
コンストラクタ
bool IsPassed(DWORD dwTime) const
[確認] 経過確認.
bool IsPassedAndReset(DWORD dwTime)
[確認] 経過確認&リセット.
LONGLONG GetPassedCount(void) const
[取得] 経過時間取得.
void OutputDebugPassedCount(void) const
[出力] 経過時間表示.
DWORD GetResolutionNanoCount(void) const
[取得] 分解度時間取得.
void Reset(void)
[設定] リセット.
LONGLONG GetPassedNanoCount(void) const
[取得] 経過時間取得.
TNB Library
Definition: TnbDoxyTitle.txt:2