Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 63b5d45

Browse files
kush-kothari-armPrzemekWirkus
authored andcommitted
[wperf, wperf-test] WPERF-965: Refactor to turn repeated code into a seperate function
See merge request Linaro/WindowsPerf/windowsperf!684 === ChangeLog === * code tidy for timestamps_to_duration function * refactor to make calculation of 'duration' from 'timestamps' into a seperate function/file
1 parent 227dbb9 commit 63b5d45

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

wperf/main.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,7 @@ wmain(
390390
pmu_device.print_dmc_stat(request.ioctl_events[EVT_DMC_CLK], request.ioctl_events[EVT_DMC_CLKDIV2], request.report_ddr_bw_metric);
391391
}
392392

393-
ULARGE_INTEGER li_a, li_b;
394-
FILETIME time_a, time_b;
395-
396-
SystemTimeToFileTime(&timestamp_a, &time_a);
397-
SystemTimeToFileTime(&timestamp_b, &time_b);
398-
li_a.u.LowPart = time_a.dwLowDateTime;
399-
li_a.u.HighPart = time_a.dwHighDateTime;
400-
li_b.u.LowPart = time_b.dwLowDateTime;
401-
li_b.u.HighPart = time_b.dwHighDateTime;
402-
403-
const double duration = (double)(li_b.QuadPart - li_a.QuadPart) / 10000000.0;
393+
const double duration = timestamps_to_duration(timestamp_a, timestamp_b);
404394
m_globalJSON.m_duration = duration;
405395

406396
if (!request.do_timeline)
@@ -1290,17 +1280,7 @@ wmain(
12901280
<< std::wstring(PrettyTable<wchar_t>::m_COLUMN_SEPARATOR, L' ') << L"top " << std::dec << printed_sample_num << L" in total" << std::endl;
12911281
}
12921282

1293-
ULARGE_INTEGER li_a, li_b;
1294-
FILETIME time_a, time_b;
1295-
1296-
SystemTimeToFileTime(&timestamp_a, &time_a);
1297-
SystemTimeToFileTime(&timestamp_b, &time_b);
1298-
li_a.u.LowPart = time_a.dwLowDateTime;
1299-
li_a.u.HighPart = time_a.dwHighDateTime;
1300-
li_b.u.LowPart = time_b.dwLowDateTime;
1301-
li_b.u.HighPart = time_b.dwHighDateTime;
1302-
1303-
const double duration = (double)(li_b.QuadPart - li_a.QuadPart) / 10000000.0;
1283+
const double duration = timestamps_to_duration(timestamp_a, timestamp_b);
13041284
m_globalJSON.m_duration = duration;
13051285

13061286
if (!request.do_timeline)

wperf/wperf.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,21 @@ GetDevicePath(
122122

123123
return bRet;
124124
}
125+
126+
double timestamps_to_duration(const SYSTEMTIME& timestamp_a, const SYSTEMTIME& timestamp_b)
127+
{
128+
ULARGE_INTEGER li_a, li_b;
129+
FILETIME time_a, time_b;
130+
131+
SystemTimeToFileTime(&timestamp_a, &time_a);
132+
SystemTimeToFileTime(&timestamp_b, &time_b);
133+
134+
li_a.u.LowPart = time_a.dwLowDateTime;
135+
li_a.u.HighPart = time_a.dwHighDateTime;
136+
li_b.u.LowPart = time_b.dwLowDateTime;
137+
li_b.u.HighPart = time_b.dwHighDateTime;
138+
139+
double duration = (double)(li_b.QuadPart - li_a.QuadPart) / 10000000.0;
140+
141+
return duration;
142+
}

wperf/wperf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ GetDevicePath(
3838
_Out_writes_(BufLen) PWCHAR DevicePath,
3939
_In_ size_t BufLen
4040
);
41+
42+
double timestamps_to_duration(const SYSTEMTIME& timestamp_a, const SYSTEMTIME& timestamp_b);

0 commit comments

Comments
 (0)