Skip to content

Commit 4e5a2ed

Browse files
Merge pull request #40 from intel-innersource/feature/non-zero-avg
Feature/non zero avg
2 parents d39e7b0 + 5def7d0 commit 4e5a2ed

File tree

9 files changed

+36
-16
lines changed

9 files changed

+36
-16
lines changed

IntelPresentMon/AppCef/Web/src/views/LoadoutConfigView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export default Vue.extend({
193193
flex: 3;
194194
}
195195
.widget-row .widget-cell.col-stat {
196-
width: 90px;
196+
width: 110px;
197197
}
198198
.widget-row .widget-cell.col-type {
199199
width: 120px;

IntelPresentMon/CommonUtilities/str/String.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (C) 2022 Intel Corporation
22
// SPDX-License-Identifier: MIT
33
#include "String.h"
4-
#include <stdlib.h>
54
#include <sstream>
65
#include <iomanip>
6+
// TODO: replace with with properly wrapped winapi include
7+
#include <Windows.h>
78

89
namespace pmon::util::str
910
{
@@ -27,25 +28,34 @@ namespace pmon::util::str
2728

2829
std::wstring ToWide(const std::string& narrow)
2930
{
31+
if (narrow.empty()) {
32+
return {};
33+
}
3034
std::wstring wide;
35+
// TODO: replace with resize_and_overwrite when it becomes widely available
3136
wide.resize(narrow.size() + 1);
32-
size_t actual;
33-
mbstowcs_s(&actual, wide.data(), wide.size(), narrow.c_str(), _TRUNCATE);
34-
if (actual > 0)
35-
{
36-
wide.resize(actual - 1);
37+
const auto actual = MultiByteToWideChar(CP_UTF8, 0, narrow.data(), (int)narrow.size(), wide.data(), (int)wide.size());
38+
if (actual > 0) {
39+
wide.resize(actual);
3740
return wide;
3841
}
42+
// TODO: log error here
3943
return {};
4044
}
4145

4246
std::string ToNarrow(const std::wstring& wide)
4347
{
4448
std::string narrow;
49+
// TODO: replace with resize_and_overwrite when it becomes widely available
4550
narrow.resize(wide.size() * 2);
46-
size_t actual;
47-
wcstombs_s(&actual, narrow.data(), narrow.size(), wide.c_str(), _TRUNCATE);
48-
narrow.resize(actual - 1);
49-
return narrow;
51+
const auto actual = WideCharToMultiByte(CP_UTF8, 0, wide.data(), (int)wide.size(),
52+
narrow.data(), (int)narrow.size(), nullptr, nullptr);
53+
if (actual > 0) {
54+
narrow.resize(actual);
55+
return narrow;
56+
}
57+
// TODO: (maybe) check for insufficient buffer error and do redo with two-pass (or just double buffer again)
58+
// TODO: log error here
59+
return {};
5060
}
5161
}

IntelPresentMon/Interprocess/source/metadata/EnumStat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
X_(STAT, MID_LERP, "Mid Lerp", "mlp", "Linear interpolation between the two observations nearest to the middle of the sliding window") \
1818
X_(STAT, NEWEST_POINT, "Newest Point", "npt", "Value in the most recent observation in the sliding window") \
1919
X_(STAT, OLDEST_POINT, "Oldest Point", "opt", "Value in the least recent observation in the sliding window") \
20-
X_(STAT, COUNT, "Count", "cnt", "Count of observations in the sliding window matching a predicate (e.g. counting # of observations for which a field is boolean true)")
20+
X_(STAT, COUNT, "Count", "cnt", "Count of observations in the sliding window matching a predicate (e.g. counting # of observations for which a field is boolean true)") \
21+
X_(STAT, NON_ZERO_AVG, "Non-zero Average", (const char*)u8"øavg", "Average or mean of frame samples over the sliding window, excluding all zero values")

IntelPresentMon/Interprocess/source/metadata/EnumUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
X_(UNIT, KILOHERTZ, "Kilohertz", "kHz", "Frequency in thousands of cycles per second") \
2424
X_(UNIT, MEGAHERTZ, "Megahertz", "MHz", "Frequency in millions of cycles per second") \
2525
X_(UNIT, GIGAHERTZ, "Gigahertz", "GHz", "Frequency in billions of cycles per second") \
26-
X_(UNIT, CELSIUS, "Degrees Celsius", "C", "Temperature in degrees Celsius") \
26+
X_(UNIT, CELSIUS, "Degrees Celsius", (const char*)u8"°C", "Temperature in degrees Celsius") \
2727
X_(UNIT, RPM, "Revolutions per Minute", "RPM", "Angular speed in revolutions per minute") \
2828
X_(UNIT, BITS_PER_SECOND, "Bits per Second", "bps", "Bandwidth / data throughput in bits per second") \
2929
X_(UNIT, KILOBITS_PER_SECOND, "Kilobits per Second", "kbps", "Bandwidth / data throughput in kilobits per second") \

IntelPresentMon/Interprocess/source/metadata/MetricList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
\
3737
X_(PM_METRIC_GPU_LATENCY, PM_METRIC_TYPE_DYNAMIC_FRAME, PM_UNIT_MILLISECONDS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_INDEPENDENT, FULL_STATS) \
3838
X_(PM_METRIC_DISPLAY_LATENCY, PM_METRIC_TYPE_DYNAMIC_FRAME, PM_UNIT_MILLISECONDS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_INDEPENDENT, FULL_STATS) \
39-
X_(PM_METRIC_CLICK_TO_PHOTON_LATENCY, PM_METRIC_TYPE_DYNAMIC_FRAME, PM_UNIT_MILLISECONDS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_INDEPENDENT, FULL_STATS) \
39+
X_(PM_METRIC_CLICK_TO_PHOTON_LATENCY, PM_METRIC_TYPE_DYNAMIC_FRAME, PM_UNIT_MILLISECONDS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_INDEPENDENT, PM_STAT_NON_ZERO_AVG, PM_STAT_PERCENTILE_01, PM_STAT_PERCENTILE_05, PM_STAT_PERCENTILE_10, PM_STAT_MAX) \
4040
X_(PM_METRIC_INPUT_LATENCY, PM_METRIC_TYPE_DYNAMIC_FRAME, PM_UNIT_MILLISECONDS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_INDEPENDENT, FULL_STATS) \
4141
\
4242
X_(PM_METRIC_GPU_SUSTAINED_POWER_LIMIT, PM_METRIC_TYPE_STATIC, PM_UNIT_WATTS, PM_DATA_TYPE_DOUBLE, PM_DATA_TYPE_DOUBLE, 0, PM_DEVICE_TYPE_GRAPHICS_ADAPTER, PM_STAT_NONE) \

IntelPresentMon/PMInstaller/PresentMon.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Id="*"
55
Name="Intel(R) PresentMon"
66
Language="1033"
7-
Version="0.7.0.0"
7+
Version="2.0.0.0"
88
Manufacturer="Intel(R) Corporation"
99
UpgradeCode="CD0D489E-0FE7-452D-90D9-F94F3F5FF410">
1010

IntelPresentMon/PresentMonAPI2/PresentMonAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ extern "C" {
191191
PM_STAT_NEWEST_POINT,
192192
PM_STAT_OLDEST_POINT,
193193
PM_STAT_COUNT,
194+
PM_STAT_NON_ZERO_AVG,
194195
};
195196

196197
enum PM_DATA_TYPE

IntelPresentMon/PresentMonMiddleware/source/ConcreteMiddleware.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cassert>
88
#include <cstdlib>
99
#include <Shlwapi.h>
10+
#include <numeric>
1011
#include "../../PresentMonUtils/NamedPipeHelper.h"
1112
#include "../../PresentMonUtils/QPCUtils.h"
1213
#include "../../PresentMonAPI2/Internal.h"
@@ -1126,6 +1127,13 @@ void ReportMetrics(
11261127
output /= inData.size();
11271128
return;
11281129
}
1130+
else if (stat == PM_STAT_NON_ZERO_AVG)
1131+
{
1132+
std::vector<double> non_zero_data;
1133+
std::copy_if(inData.begin(), inData.end(), std::back_inserter(non_zero_data),
1134+
[](double value) { return value != 0.0; });
1135+
output = !non_zero_data.empty() ? std::accumulate(non_zero_data.begin(), non_zero_data.end(), 0.0) / non_zero_data.size() : 0.0;
1136+
}
11291137
else if (stat == PM_STAT_MID_POINT)
11301138
{
11311139
size_t middle_index = inData.size() / 2;

IntelPresentMon/Streamer/StreamClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const PmNsmFrameData* StreamClient::PeekPreviousFrame()
228228

229229
PM_STATUS StreamClient::ConsumePtrToNextNsmFrameData(const PmNsmFrameData** pNsmData)
230230
{
231-
if (*pNsmData == nullptr) {
231+
if (pNsmData == nullptr) {
232232
return PM_STATUS::PM_STATUS_FAILURE;
233233
}
234234

0 commit comments

Comments
 (0)