两个进程的RAM消耗具有相同的名称 [英] The RAM consumption of two process with the same name
本文介绍了两个进程的RAM消耗具有相同的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查两个SQL实例的RAM消耗。问题是它们在任务管理器中都出现了相同的名称(SQL Server Windows NT)。我做了一些研究,我设法提出了一个代码,但问题是它给了我一个实例的
RAM消耗,而不是两个实例。
这是我的代码。
public void checkram()
{
try
{
int memsize = 0;
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName =" Process";
PC.CounterName =" Working Set - Private" ;;
foreach(Process.GetProcessesByName(" sqlservr")中的var进程)
{
PC.InstanceName =进程。 ProcessName;
memsize = Convert.ToInt32(PC.NextValue())/(int)(1024 * 1024);
Console.WriteLine(PC.InstanceName," \ n");
Console.WriteLine(" Memory used:{0}。",memsize);
}
PC.Close();
PC.Dispose();
}
catch(exception ex)
{
Console.WriteLine(ex.Message," Error");
}
}
GetProcessInstanceName 函数来自
CpuMeter.cs
在您的示例中:
PC.InstanceName = GetProcessInstanceName(process.Id);
它给我一个错误。
严重性 代码
描述 项目
文件 Line
抑制州
错误 CS0103
名称'当前上下文中不存在"GetProcessInstanceName"
67 活动>
I need to check the RAM consumption of two SQL instances. The problems is that they all appear with the same name (SQL Server Windows NT) in the task manager. I did some research and I managed to come up with a code, but the problem is that it gives me the RAM consumption for one of the instances, not for the two of them.
Here is my code.
public void checkram() { try { int memsize = 0; PerformanceCounter PC = new PerformanceCounter(); PC.CategoryName = "Process"; PC.CounterName = "Working Set - Private"; foreach (var process in Process.GetProcessesByName("sqlservr")) { PC.InstanceName = process.ProcessName; memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024*1024); Console.WriteLine(PC.InstanceName, "\n"); Console.WriteLine("Memory used: {0}.", memsize); } PC.Close(); PC.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message, "Error"); } }
解决方案
Use the GetProcessInstanceName function from CpuMeter.cs
In your sample :
PC.InstanceName = GetProcessInstanceName(process.Id);
It is giving me an error.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'GetProcessInstanceName' does not exist in the current context 67 Active
这篇关于两个进程的RAM消耗具有相同的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文