当我创建和使用这样的性能计数器时:
private readonly PerformanceCounter _cpuPerformanceCounter;
public ProcessViewModel(Process process)
{
_cpuPerformanceCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName, true);
}
public void Update()
{
CPU = (int)_cpuPerformanceCounter.NextValue() / Environment.ProcessorCount; // Exception
}
Run Code Online (Sandbox Code Playgroud)
...我得到一个异常实例"实例的名称"在指定的类别中不存在,并且不理解原因.
PS代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<settings>
<performanceCounters enabled="true"/>
</settings>
</system.net>
</configuration>
Run Code Online (Sandbox Code Playgroud)
...包含在App.config中.
我正在尝试为在2个不同服务器上运行的程序构建负载均衡器.
到目前为止,我的负载均衡器只使用每个服务器程序中的PerformanceCounter实例来检查每个服务器的CPU使用情况.
我还想检查每个服务器的带宽使用情况,我该如何检查?
(它可能也是使用PerformanceCounter完成的,但我不熟悉它的用法)
我正在尝试使用PerformanceCounter类通过C#访问位于".NET CLR内存类别"中的性能计数器.但是,无法使用我期望的正确类别/计数器名称来实例化类别
new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName);
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码循环遍历类别和计数器
string[] categories = PerformanceCounterCategory.GetCategories().Select(c => c.CategoryName).OrderBy(s => s).ToArray();
string toInspect = string.Join(",\r\n", categories);
System.Text.StringBuilder interestingToInspect = new System.Text.StringBuilder();
string[] interestingCategories = categories.Where(s => s.StartsWith(".NET") || s.Contains("Memory")).ToArray();
foreach (string interestingCategory in interestingCategories)
{
PerformanceCounterCategory cat = new PerformanceCounterCategory(interestingCategory);
foreach (PerformanceCounter counter in cat.GetCounters())
{
interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
}
}
toInspect = interestingToInspect.ToString();
Run Code Online (Sandbox Code Playgroud)
但找不到任何似乎匹配的东西.是不可能从CLR中观察这些值,或者我做错了什么.
重要的是,环境是在64位Windows 7机器上运行的.NET 4.0.
在Windows下,性能计数器具有不同的名称,具体取决于操作系统语言.例如,在英文版Windows上,有性能计数器\Processor(_Total)\% Processor Time.\Prozessor(_Total)\Prozessorzeit (%)在德语Windows版本上调用相同的计数器.
有没有办法以与语言无关的方式检索性能计数器值(使用C++或C#)?或者有没有替代方案来获得整个计算机的处理器负载而没有性能计数器?
我使用以下代码创建了一个自定义性能计数器:
public class PerfCounter
{
private PerformanceCounter perfCounter;
PerfCounter(string CategoryName, string CounterName)
{
perfCounter = new PerformanceCounter(CategoryName, CounterName, false);
perfCounter.BeginInit();
}
public void IncrementBy(long value)
{
perfCounter.IncrementBy(value);
}
public void Reset()
{
//what should I add here?
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但我不知道如何重置柜台.谁能帮我?
我看到事件ID 2001与错误消息:
刷新W3SVC计数器花了太长时间,而是使用过时的计数器.
事件源:IIS-W3SVC-PerfCounters.
这发生在Windows Server 2008 R2上,在此服务器上我们没有启用Perf计数器,但我仍然看到这些错误.我担心这可能会影响IIS.有人可以帮我吗?在Advance中感谢您的帮助!
关于此主题有一些问题,但没有一个是真正的答案。问题是:如何测量macOS上的L1,L2,L3(如果有)缓存未命中?
问题在于,即使没有任何外部工具,macOS在理论上也不会提供这些值。在乐器中,我们可以使用计数器并转到录音选项...,如下所示:
但是,不存在L1高速缓存未命中或L2高速缓存,但是可以选择的可能项目数量庞大:
因此,在测量L1和L2 高速缓存未命中率(或L3,如果有的话)时,如何计算它们?
为了检索该神奇的“缓存未命中”数字,我应该注意哪个列表“ 缓存未命中”?
performance x86 caching performancecounter xcode-instruments
我正在运行一些关于为一段代码获得高度一致的运行时的实验。我目前正在计时的代码是一个非常任意的受 CPU 限制的工作负载:
int cpu_workload_external_O3(){
int x = 0;
for(int ind = 0; ind < 12349560; ind++){
x = ((x ^ 0x123) + x * 3) % 123456;
}
return x;
}
Run Code Online (Sandbox Code Playgroud)
我编写了一个内核模块,它禁用中断,然后运行上述函数的 10 次试验,通过获取前后时钟周期计数器的差异来对每次试验进行计时。其他注意事项:
换句话说,我相信系统可变性的大多数/所有来源都被考虑在内,尤其是当作为内核模块运行时,通过禁用中断spin_lock_irqsave(),代码应该实现几乎相同的运行到运行性能(可能是一个小的性能损失在第一次运行时,当一些指令第一次被拉入缓存时,但就是这样)。
实际上,当使用 编译基准代码时-O3,我看到平均范围内最多 200 个周期,其中大约 135,845,192 个周期,大多数试验花费的时间完全相同。但是,当使用 编译时-O0,范围高达 ~262,710,916 中的 158,386 个周期。我所说的范围是指最长和最短运行时间之间的差异。此外,对于-O0代码,对于哪个试验是最慢/最快的并没有太大的一致性——与直觉相反,有一次,最快的是第一个,最慢的是紧随其后的!
那么:什么可能导致-O0代码可变性的上限如此之高?查看程序集,-O3代码似乎将所有内容(?)存储在寄存器中,而-O0代码有一堆对等的引用sp,因此它似乎正在访问内存。但即便如此,我还是希望所有内容都能进入 L1 …
performance assembly arm performancecounter cpu-architecture
好吧,前几天我将特定代码片段的性能从34秒提高到2秒,我正在计算相同的百分比,即(34-2)/ 34,即94.11%,当我在会议中告诉这个数字时没有那么惊讶..我想知道这是否是我传达的错误号码..
你如何衡量改进并同时看起来很好?
我想测量我的 C++ 代码某些部分的 L1、L2 和 L3 缓存命中/未命中率。我对在我的整个应用程序中使用 Perf 不感兴趣。Perf 可以用作 C++ 中的库吗?
int main() {
...
...
start_profiling()
// The part I'm interested in
...
end_profiling()
...
...
}
Run Code Online (Sandbox Code Playgroud)
我给了英特尔 PCM 一个机会,但我遇到了两个问题。首先,它给了我一些奇怪的数字。其次,它不支持 L1 缓存分析。
如果 Perf 无法实现,那么获取该信息的最简单方法是什么?