下面代码的轨迹都是断的,不是一条平滑的曲线。这是我的程序片段。我的采样率是1秒,我已经尝试了所有可能的采样值。我还尝试了下面的代码,只使用PerfSetULongLongCounterValue(),不使用递减/递增调用。这也无济于事。必须有一种方法/设置来告诉Perfmon,如果传入的值是100、200、300、500、300、200、100,则绘制正弦波。当我以1秒的间隔给出正弦波数据时,我得到的是不相交的线。请帮帮忙。
PerfSetULongLongCounterValue(abcd, GPerfInstance0[0], TOT_MBW_ID, 0);
ULONGLONG counterValue = 0, oldCounterValue = 0;
SYSTEMTIME sysTime;
while (!_kbhit()) {
counterValue = 30+ (rand() % 10)*100;
if (counterValue > oldCounterValue) {
PerfIncrementULongLongCounterValue(abcd, GPerfInstance0[0], TOT_MBW_ID, llabs(counterValue - oldCounterValue));
} else if (counterValue < oldCounterValue) {
PerfDecrementULongLongCounterValue(abcd, GPerfInstance0[0], TOT_MBW_ID, llabs(counterValue - oldCounterValue));
} else {
PerfSetULongLongCounterValue(abcd, GPerfInstance0[0], TOT_MBW_ID, counterValue);
}
GetSystemTime(&sysTime);
cout << counterValue << ", " << sysTime.wMinute << ":" << sysTime.wSecond << "\n";
oldCounterValue = counterValue;
Sleep(1000);
}我被指向这个示例代码:https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/winbase/PerfCounters/Basic/CPP/ucs.c,这确实可以很好地工作,但是当我在我的代码中尝试相同的代码时,PerfSetCounterRefValue()错误地显示为0x57 INVALID_PARAMETER。所以我放弃了。至少上面的代码运行得更好,并且需要在某个地方做一些小调整。任何帮助都将不胜感激。
发布于 2019-12-11 07:49:24
微软在这里提供了一个示例代码:https://github.com/microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/winbase/PerfCounters/Basic/CPP这个示例有一个问题,我无法让PerfSetCounterRefValue()工作。它抱怨ERROR_INVALID_PARAMETER (0x57)。我的代码没有使用它。另一个问题是使用PerfSetULongLongCounterValue(),如果我使用它而不是PerfIncrementULongLongCounterValue(),我的跟踪中断不会得到连续的跟踪。
好了,我终于让它工作了。这是正确的/官方的方式吗?我不知道。在我的例子中,它工作得很好,并且忠实地跟踪输入的值。
ULONGLONG initValue = 0;
ULONGLONG currentValue = 0;
SYSTEMTIME sysTime;
PerfSetULongLongCounterValue(HandleX, PerfInstance, 1, initValue);
while (!_kbhit()) {
currentValue = (rand() % 10)*100;
GetSystemTime(&sysTime);
PerfIncrementULongLongCounterValue(HandleX, PerfInstance, 1, currentValue);
cout << sysTime.wMinute << ":" << sysTime.wSecond << " " << currentValue << "\n";
Sleep(1000);
}
return 0;https://stackoverflow.com/questions/59148557
复制相似问题