Tag: performancecounter

如何在不删除旧计数器的情况下将新计数器添加到现有性能计数器类别?

我有一个自定义计数器类别,我需要添加一个新的计数器,而不删除或重置任何现有的计数器。 我怎样才能做到这一点? 我尝试使用CounterExists(),但即使在我创建计数器之后,如何将它与CounterCreationDataCollection项关联并将其与我现有的计数器类别相关联?

性能计数器当前进程的CPU使用率超过100

我想显示我的multithreading应用程序的CPU使用率(在多核处理器上工作)。 我想收到任务经理附近的数字。 但我得到的数字超过100%。 甚至超过500%。 是的,我知道,对于类别“进程”的计数器“%Processor Time”我需要分为Environment.ProcessorCount或“NumberOfLogicalProcessors” (我的配置相同)。 此操作后结果为500%。 我在具有不同硬件(i7,i5,Core2)和软件配置(带有所有更新的Windows 7 SP1,带有所有更新的Windows 2008 R2 SP1)的不同计算机上测试了此示例,并遇到了同样的问题。 public static class SystemInfo { private static Process _thisProc; private static bool HasData = false; private static PerformanceCounter _processTimeCounter; private static void Init() { if (HasData) return; if (CheckForPerformanceCounterCategoryExist(“Process”)) { _processTimeCounter = new PerformanceCounter(); _processTimeCounter.CategoryName = “Process”; _processTimeCounter.CounterName = “% Processor […]

检索计算机上的RAM总量

可能重复: C# – 如何获得计算机的RAM总量? 以下将检索有多少ram可用: PerformanceCounter ramCounter; ramCounter = new PerformanceCounter(“Memory”, “Available MBytes”); Console.WriteLine(“Total RAM: ” + ramCounter.NextValue().ToString() + ” MB\n\n”); 当然我们必须使用System.Diagnostics; 类。 performancecounter是否具有检索特定计算机的RAM量的任何function? 我不是在谈论使用或未使用的ram数量。 我在谈论机器的内存量。

多处理器和PerformanceCounter C#

我正在试图弄清楚如何收集计算机上每个处理器的当前使用百分比。 如果我使用“System.Environment.ProcessorCount;” 我可以获得计算机上的处理器数量,它当前返回“2”。 我要么不知道我在找什么,要么在网上没有太多关于此的信息。 以下是我目前用于获取所有处理器总当前使用百分比的代码。 protected PerformanceCounter cpuCounter = new PerformanceCounter(“processor”, “% Processor Time”, “_Total”); public string getCurrentCpuUsage() { return cpuCounter.NextValue() + “%”; } 感谢您的任何帮助, 亚伦

在C#程序中,我试图获取应用程序的CPU使用百分比,但它总是显示100

这是我的代码。 PerformanceCounter cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = “Processor”; cpuCounter.CounterName = “% Processor Time”; cpuCounter.InstanceName = “_Total”; // will always start at 0 dynamic firstValue = cpuCounter.NextValue(); System.Threading.Thread.Sleep(1000); dynamic secondValue = cpuCounter.NextValue(); return secondValue; 这里有很多人正在解决这个问题,即返回零,但我总是得到100,而且我确信我的软件没有占用那么多的CPU粉末。 关于我能做些什么来使这项工作正确的任何想法。 为了清楚起见,我试图从运行此代码的应用程序中检索处理器使用情况,而不是单独的代码。 我也在运行VM,但这似乎并不重要。 有任何想法吗?

RateOfCountsPerSecond32类型的计数器始终显示0

我有一个Windows服务,通过WCF服务接口提供某些虚拟队列的消息。 我想揭露两个性能指标 – 队列中的项目数 每秒从队列中删除的项目数 第一个工作正常,第二个在PerfMon.exe中始终显示为0,尽管RawValue看起来是正确的。 我正在创建计数器 – internal const string PERF_COUNTERS_CATEGORY = “HRG.Test.GDSSimulator”; internal const string PERF_COUNTER_ITEMSINQUEUE_COUNTER = “# Messages on queue”; internal const string PERF_COUNTER_PNR_PER_SECOND_COUNTER = “# Messages read / sec”; if (!PerformanceCounterCategory.Exists(PERF_COUNTERS_CATEGORY)) { System.Diagnostics.Trace.WriteLine(“Creating performance counter category: ” + PERF_COUNTERS_CATEGORY); CounterCreationDataCollection counters = new CounterCreationDataCollection(); CounterCreationData numberOfMessagesCounter = new CounterCreationData(); numberOfMessagesCounter.CounterHelp = […]

从C#读取性能计数器:指定类别中不存在实例

我正在尝试从另一个.NET 4应用程序中运行的.NET 4应用程序中读取许多性能计数器。 某些计数器,例如Process\% Processor Time和Process\Private Bytes工作正常。 但是,只要我尝试从其中一个.NET类别(例如.NET CLR Memory\# Gen 0 Collections读取性能计数器,就会出现以下exception: Instance ‘MyApplication’ does not exist in the specified Category 我打电话的时候: new PerformanceCounterCategory(“.NET CLR Memory”).GetInstanceNames() 它返回一组非常小的实例,MyApplication确实不在列表中。 但是,当我在perfmon查看我的性能计数器时,我在同一类别/计数器中看到的实例列表要长得多,并且包括MyApplication。 有谁知道为什么我的应用程序看不到.NET计数器? (注意:受监视的应用程序由监视应用程序启动 ,因此它们肯定在同一用户帐户中运行。我还尝试以管理员身份启动我的监视应用程序并将我的帐户添加到Performance Monitor Users组,但不起作用。)

PerformanceCounter报告的CPU使用率高于观察到的CPU使用率

我目前正在这样做: PerformanceCounter cpuUsage = new PerformanceCounter(“Processor”, “% Processor Time”, “_Total”); cpuUsage.NextValue(); System.Threading.Thread.Sleep(1000); RV = cpuUsage.NextValue(); 我定期调用该函数以获得CPU使用率。 当我在TaskManager中监视系统时,PerformanceCounter报告的CPU使用率始终比TaskManager报告的高出15-20%(TaskManager中的30%=来自PerformanceCounter的50%)。 也许有我忽略的文档,但有没有人有解释? 也许它检查的瞬间CPU使用率更高,任务管理器报告平均值?

性能计数器 – System.InvalidOperationException:类别不存在

我有以下类返回IIS当前每秒请求数。 我每分钟调用RefreshCounters以保持每秒请求数值的刷新(因为它是平均值,如果我保持太长时间,旧值会影响结果太多)……当我需要显示当前的RequestsPerSecond时,我会调用该属性。 public class Counters { private static PerformanceCounter pcReqsPerSec; private const string counterKey = “Requests_Sec”; public static object RequestsPerSecond { get { lock (counterKey) { if (pcReqsPerSec != null) return pcReqsPerSec.NextValue().ToString(“N2”); // EXCEPTION else return “0”; } } } internal static string RefreshCounters() { lock (counterKey) { try { if (pcReqsPerSec != null) { […]

列出所有进程及其当前内存和CPU消耗?

如何获取C#中的所有进程列表,然后获取每个进程的当前内存和CPU消耗? 示例代码非常感谢。