Skip to content

Commit a9b52cc

Browse files
committed
more accurate time measurements in DbgMsgSrc
1 parent 8a2f58b commit a9b52cc

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

DbgMsgSrc/DbgMsgSrc.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sys/timeb.h>
1818
#include "Win32/Win32Lib.h"
1919
#include "dbgstream.h"
20+
#include "Timer.h"
2021

2122
#pragma comment(lib, "Ws2_32.lib")
2223
#pragma comment(lib, "psapi.lib")
@@ -194,20 +195,14 @@ void Output(const std::string& filename)
194195
fs.close();
195196

196197
std::cout << "writing... " << lines.size() << " lines\n";
197-
198-
int i = 0;
199-
long t1 = getMilliCount();
200-
201-
for (auto s = lines.begin(); s != lines.end(); ++s)
198+
Timer timer;
199+
auto t1 = timer.now();
200+
for (const auto& s : lines)
202201
{
203-
++i;
204-
//auto t = s + "\n";
205-
OutputDebugStringA(s->c_str());
206-
//Sleep(50);
202+
OutputDebugStringA(s.c_str());
207203
}
208-
long t2 = getMilliCount();
209-
210-
std::cout << "OutputDebugStringA " << i << " lines, took: " << t2 - t1 << " ms\n";
204+
auto elepsed = timer.now() - t1;
205+
std::cout << "OutputDebugStringA " << lines.size() << " lines, took: " << static_cast<int>(Timer::ToMs(elepsed)) << " ms\n";
211206
}
212207

213208
void EndlessTest()

DbgMsgSrc/DbgMsgSrc.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@
157157
</ItemDefinitionGroup>
158158
<ItemGroup>
159159
<ClCompile Include="DbgMsgSrc.cpp" />
160+
<ClCompile Include="Timer.cpp" />
160161
</ItemGroup>
161162
<ItemGroup>
162163
<ClInclude Include="dbgstream.h" />
164+
<ClInclude Include="Timer.h" />
163165
</ItemGroup>
164166
<ItemGroup>
165167
<ProjectReference Include="..\Win32Lib\Win32Lib.vcxproj">

DbgMsgSrc/DbgMsgSrc.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
<ClCompile Include="DbgMsgSrc.cpp">
1919
<Filter>Source Files</Filter>
2020
</ClCompile>
21+
<ClCompile Include="Timer.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
2124
</ItemGroup>
2225
<ItemGroup>
2326
<ClInclude Include="dbgstream.h">
2427
<Filter>Header Files</Filter>
2528
</ClInclude>
29+
<ClInclude Include="Timer.h">
30+
<Filter>Header Files</Filter>
31+
</ClInclude>
2632
</ItemGroup>
2733
<ItemGroup>
2834
<None Include="packages.config" />

DbgMsgSrc/Timer.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdexcept>
2+
#include <chrono>
3+
#include "Timer.h"
4+
5+
#define MICROSECONDS (1e6 / li.QuadPart)
6+
7+
Timer::Timer()
8+
: m_timerUnit(0.0)
9+
{
10+
LARGE_INTEGER li;
11+
QueryPerformanceFrequency(&li);
12+
if (li.QuadPart == 0)
13+
throw std::runtime_error("QueryPerformanceCounter not supported!");
14+
m_timerUnit = MICROSECONDS;
15+
}
16+
17+
std::chrono::steady_clock::time_point Timer::now() const
18+
{
19+
return std::chrono::steady_clock::time_point(std::chrono::microseconds(static_cast<long long>(GetTicks() * m_timerUnit)));
20+
}
21+
22+
long long Timer::GetTicks() const
23+
{
24+
LARGE_INTEGER li;
25+
QueryPerformanceCounter(&li);
26+
return li.QuadPart;
27+
}

DbgMsgSrc/Timer.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <mutex>
4+
#include <chrono>
5+
#include <windows.h>
6+
7+
class Timer
8+
{
9+
public:
10+
Timer();
11+
std::chrono::steady_clock::time_point now() const;
12+
13+
static double ToMs(std::chrono::steady_clock::duration duration)
14+
{
15+
return static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(duration).count()) / 1000.0;
16+
}
17+
18+
private:
19+
long long GetTicks() const;
20+
double m_timerUnit;
21+
};

OutputForwarderVSIX/Forwarder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private Forwarder(Package package)
5353
InstallForwarder(package);
5454
}
5555

56-
private void InstallForwarder(Package)
56+
private void InstallForwarder(Package package)
5757
{
5858
IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
5959
Guid paneGuid = VSConstants.GUID_OutWindowDebugPane; // codenotes: GUID_BuildOutputWindowPane / GUID_OutWindowDebugPane

0 commit comments

Comments
 (0)