本文整理汇总了C#中System.Diagnostics.PerformanceCounter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.Close方法的具体用法?C# PerformanceCounter.Close怎么用?C# PerformanceCounter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.PerformanceCounter
的用法示例。
在下文中一共展示了PerformanceCounter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Scheduler
/// <summary>
/// This method is responsible for monitoring system resource and user activity with the computer
/// And periodically changes the shared variable 'crawlerState'
/// </summary>
public void Scheduler()
{
PerformanceCounter pc = new PerformanceCounter("Processor", "% Idle Time", "_Total", true);
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
while (GlobalData.RunScheduler)
{
if (GetLastInputInfo(ref info))
{
if ((Environment.TickCount - info.dwTime) / 1000 > 5 && (int)pc.NextValue() > 40)
{
crawlerState = CrawlerState.Run;
}
else
{
crawlerState = CrawlerState.Stop;
if ((Environment.TickCount - info.dwTime) / 1000 <= 5)
GlobalData.lIndexingStatus.Text = string.Format("Indexing is paused and will be resumed in {0} sec of computer inactivity [ CPU Idle : {1:F2}% ]", 5 - (Environment.TickCount - info.dwTime) / 1000, pc.NextValue());
}
}
Thread.Sleep(1000);
}
pc.Close();
}
示例2: LogAspThreads
void LogAspThreads()
{
int availableWorker, availableIO;
int maxWorker, maxIO;
ThreadPool.GetAvailableThreads(out availableWorker, out availableIO);
ThreadPool.GetMaxThreads(out maxWorker, out maxIO);
PerformanceCounter c = new PerformanceCounter("Mubble", "Available ASP.NET Worker Threads");
c.ReadOnly = false;
c.RawValue = availableWorker;
c.Close();
c = new PerformanceCounter("Mubble", "Available ASP.NET IO Threads");
c.ReadOnly = false;
c.RawValue = availableIO;
c.Close();
c = new PerformanceCounter("Mubble", "Max ASP.NET Worker Threads");
c.ReadOnly = false;
c.RawValue = maxWorker;
c.Close();
c = new PerformanceCounter("Mubble", "Max ASP.NET IO Threads");
c.ReadOnly = false;
c.RawValue = maxIO;
c.Close();
}
示例3: IncrementCounter
static void IncrementCounter()
{
// get an instance of our perf counter
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = "MyCategory";
counter.CounterName = "AddCounter";
counter.ReadOnly = false;
// increment and close the perf counter
counter.Increment();
counter.Close();
}
示例4: LogMubbleThreads
void LogMubbleThreads()
{
PerformanceCounter c = new PerformanceCounter("Mubble", "Available Mubble Worker Threads");
c.ReadOnly = false;
c.RawValue = Worker.MaxThreads - Worker.TotalThreads;
c.Close();
c = new PerformanceCounter("Mubble", "Max Mubble Worker Threads");
c.ReadOnly = false;
c.RawValue = Worker.MaxThreads;
c.Close();
c = new PerformanceCounter("Mubble", "Work items in Mubble queue");
c.ReadOnly = false;
c.RawValue = Worker.QueueLength;
c.Close();
}
示例5: IncrementUnhandledExceptions
private static void IncrementUnhandledExceptions()
{
try
{
string performanceCounterCategory = Assembly.GetEntryAssembly().GetName().Name;
string performanceCounterName = "UnhandledExceptions";
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = performanceCounterCategory;
counter.CounterName = performanceCounterName;
counter.ReadOnly = false;
counter.Increment();
counter.Close();
}
catch (Exception)
{
return;
}
}
示例6: GetCurrentValue
private static long GetCurrentValue()
{
try
{
string performanceCounterCategory = Assembly.GetEntryAssembly().GetName().Name;
string performanceCounterName = "UnhandledExceptions";
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = performanceCounterCategory;
counter.CounterName = performanceCounterName;
counter.ReadOnly = true;
long current = counter.RawValue;
counter.Close();
return current;
}
catch (Exception ex)
{
return 0;
}
}
示例7: PerformanceCounterTest
public void PerformanceCounterTest()
{
// Delete the Performance Counter Category, if already exists
if (PerformanceCounterCategory.Exists("SalesDistribution"))
PerformanceCounterCategory.Delete("SalesDistribution");
// Prepare for creation of the Performance Counter
CounterCreationDataCollection counterCollection =
new CounterCreationDataCollection();
//Create the CounterCreationData
CounterCreationData counterData = new CounterCreationData();
counterData.CounterName = "RequestsPerSec";
counterData.CounterType = PerformanceCounterType.NumberOfItems32;
counterData.CounterHelp = "Requests Received per Second";
counterCollection.Add(counterData);
// Create the performance counter category
PerformanceCounterCategory.Create("SalesDistribution",
"Automated Sales Distribution System",
PerformanceCounterCategoryType.SingleInstance, counterCollection);
// Retrieve the performance counter for updation
PerformanceCounter performanceCount =
new PerformanceCounter("SalesDistribution", "RequestsPerSec", false);
int x = 1;
while (x <= 50)
{
Console.WriteLine("RequestsPerSec = {0}", performanceCount.RawValue);
// Increment the performance counter
performanceCount.Increment();
System.Threading.Thread.Sleep(250);
x = (x + 1);
}
// Close the performance counter
performanceCount.Close();
}
示例8: OnTimedWpmEvent
private static void OnTimedWpmEvent(Object source, ElapsedEventArgs e)
{
wpmTimer.Stop();
try
{
for (var i = 0; i < databases.Count; i++)
{
SQLiteConnection m_dbConnection = null;
bool isToInsert = true;
try
{
int maxAge = 24;
String dbPath = databases[i].Split('=')[1];
String testCaseName = databases[i].Split('=')[0];
foreach (String maxAges in databasesMaxAge)
{
try
{
String testcaseMaxAgeName = maxAges.Split('=')[0];
int testcaseMaxAgeValue = Convert.ToInt32(maxAges.Split('=')[1]);
if (testcaseMaxAgeName == testCaseName)
{
maxAge = testcaseMaxAgeValue;
}
}
catch { }
}
m_dbConnection =
new SQLiteConnection("Data Source=" + dbPath + ";Version=3;");
m_dbConnection.Open();
//String dbName = Path.GetFileName(dbPath);
//dbName = dbName.Split('.')[0];
//String dbName = databases[i].Split('=')[0];
//check sorting
using (SQLiteCommand fmd = m_dbConnection.CreateCommand())
{
fmd.CommandText = @"SELECT * FROM sorting ORDER BY start_time DESC LIMIT 1;";
fmd.CommandType = CommandType.Text;
SQLiteDataReader r = null;
try
{
r = fmd.ExecuteReader();
}
catch
{
PerformanceCounterCategory.Delete("Alyvix - " + testCaseName);
}
//r.Read();
List<Performance> perfToQuery = new List<Performance>();
List<Performance> perfToQueryTimedOut = new List<Performance>();
while (r.Read())
{
for (int j = 0; j < r.FieldCount; j++)
{
if (j == 0) continue;
try
{
Performance perf = new Performance();
perf.name = r.GetName(j).Replace("_index", "");
perf.sort = Convert.ToInt32(r[j]);
if (perf.sort == -1)
perfToQueryTimedOut.Add(perf);
else
perfToQuery.Add(perf);
}
catch
{
}
}
//String a = Convert.ToString(r["perf_1_index"]);
}
r.Close();
perfToQuery.Sort(delegate (Performance p1, Performance p2) {
return p1.sort.CompareTo(p2.sort);
});
List<Performance> SortedList = perfToQuery;
SortedList.AddRange(perfToQueryTimedOut);
String queryPerfValue = "SELECT start_time";
//.........这里部分代码省略.........
示例9: GetPerformanceCounterValueByInstance
private static float GetPerformanceCounterValueByInstance(string perfCategory, string perfCounterName, string perfInstanceName, out string PerfCounterType, int sleep = 50)
{
PerfCounterType = "";
try
{
PerformanceCounter pc = new PerformanceCounter(perfCategory, perfCounterName, perfInstanceName);
pc.NextValue();
Thread.Sleep(sleep);
try
{
PerfCounterType = pc.CounterType.ToString();
return pc.NextValue();
}
finally
{
pc.Close();
}
}
catch
{
try
{
// Translate the category and countername to CurrentLanguage
perfCategory = LookupPerfNameByName(perfCategory);
perfCounterName = LookupPerfNameByName(perfCounterName);
PerformanceCounter pc = new PerformanceCounter(perfCategory, perfCounterName, perfInstanceName);
pc.NextValue();
Thread.Sleep(sleep);
try
{
PerfCounterType = pc.CounterType.ToString();
return pc.NextValue();
}
finally
{
pc.Close();
}
}
catch
{
// I give up, didnt manage to figure out the correct name for the PerformanceCounter.
Console.WriteLine("ERROR: Error looking up PerformanceCounter '" + perfCategory + "\\" + perfCounterName + "' for " + perfInstanceName + "'");
return -1;
}
}
}
示例10: WaringLogProcess
//.........这里部分代码省略.........
xdoc.Load(LogSettingFilePathAndName);
XmlNodeList RootNodeList = xdoc.SelectNodes("ProcessFile/add");
for (int i = 0; i < RootNodeList.Count; i++)
{
string ProcessFile = RootNodeList[i].Attributes["File"].Value;
SYSModel.LogLevel LogLevelProc = (SYSModel.LogLevel)int.Parse(RootNodeList[i].Attributes["LogLevel"].Value);
if (((ProcessFile == "*") && (LogLevelProc >= SYSModel.LogLevel.Waring)) ||
((ProcessFile == this.PageCode + ".aspx") && (LogLevelProc >= SYSModel.LogLevel.Waring))
)
{
SYSModel.LogHelper ProcLog = new SYSModel.LogHelper(ConnectionDB);
ParameterList.Clear();
//Server名稱
ParameterList.Add(Request.ServerVariables["Server_Name"]);
//模組名稱
ParameterList.Add(WebSite[2]);
//URL
ParameterList.Add(Request.Path);
//LOGLEVEL
ParameterList.Add(SYSModel.LogLevel.Waring);
//錯誤訊息
ParameterList.Add(MessageStr);
//控制項內容
ParameterList.Add("");
//SQL語法
ParameterList.Add("");
try
{
//使用者
ParameterList.Add(Session["UID"].ToString());
}
catch (Exception ex)
{
//使用者
ParameterList.Add("SessionUID Timeout");
}
PerformanceCounter PC = new PerformanceCounter();
PerformanceCounter PC1 = new PerformanceCounter();
try
{
//目前記憶體總量
PC.CategoryName = PerformanceCounter_TotalMemoryCategoryName;
PC.CounterName = PerformanceCounter_TotalMemoryCounterName;
PC.InstanceName = PerformanceCounter_TotalMemoryInstanceName;
PC.ReadOnly = true;
ParameterList.Add(PC.NextValue());
}
catch (Exception ex)
{
ParameterList.Add(-1);
}
finally
{
try
{
//未釋放的記憶體
PC1.CategoryName = PerformanceCounter_HeapMemoryCategoryName;
PC1.CounterName = PerformanceCounter_HeapMemoryCounterName;
PC1.InstanceName = PerformanceCounter_HeapMemoryInstanceName;
PC1.ReadOnly = true;
ParameterList.Add(PC1.NextValue());
}
catch (Exception ex)
{
ParameterList.Add(-1);
}
finally
{
//檢查變數項目是否足夠
ParameterListIndexCheck(WebSite[2],
SYSModel.LogLevel.Waring,
""
);
//寫入DB
ProcLog.WriteLog(ParameterList,
null
);
PC.Close();
PC1.Close();
}
}
}
}
}
示例11: InformationLogProcess
//.........这里部分代码省略.........
StringBuilder sb = new StringBuilder();
sb.Remove(0, sb.Length);
for (int j=0;j<Rqs.Length;j++)
{
//Rqs[j].ControlID = Request.Form.GetKey(j);
//Rqs[j].Value = Request.Form.GetValues(j)[0].ToString(); ;
sb.AppendFormat("控制項名稱:{0},內容{1};",
Request.Form.GetKey(j).ToString(),
Request.Form.GetValues(j)[0].ToString()
);
}
ParameterList.Clear();
//Server名稱
ParameterList.Add(Request.ServerVariables["Server_Name"]);
//模組名稱
ParameterList.Add(WebSite[2]);
//URL
ParameterList.Add(Request.Path);
//LOGLEVEL
ParameterList.Add(SYSModel.LogLevel.Information);
//錯誤訊息
ParameterList.Add("紀錄Information");
//控制項內容
ParameterList.Add(sb.ToString());
//SQL語法
ParameterList.Add("");
try
{
//使用者
ParameterList.Add(Session["UID"].ToString());
}
catch (Exception ex)
{
//使用者
ParameterList.Add("SessionUID Timeout");
}
PerformanceCounter PC = new PerformanceCounter();
PerformanceCounter PC1 = new PerformanceCounter();
try
{
//目前記憶體總量
PC.CategoryName = PerformanceCounter_TotalMemoryCategoryName;
PC.CounterName = PerformanceCounter_TotalMemoryCounterName;
PC.InstanceName = PerformanceCounter_TotalMemoryInstanceName;
PC.ReadOnly = true;
ParameterList.Add(PC.NextValue());
}
catch (Exception ex)
{
ParameterList.Add(-1);
}
finally
{
try
{
//未釋放的記憶體
PC1.CategoryName = PerformanceCounter_HeapMemoryCategoryName;
PC1.CounterName = PerformanceCounter_HeapMemoryCounterName;
PC1.InstanceName = PerformanceCounter_HeapMemoryInstanceName;
PC1.ReadOnly = true;
ParameterList.Add(PC1.NextValue());
}
catch (Exception ex)
{
ParameterList.Add(-1);
}
finally
{
//檢查變數項目是否足夠
ParameterListIndexCheck(WebSite[2],
SYSModel.LogLevel.Information,
sb.ToString()
);
//寫入DB
ProcLog.WriteLog(ParameterList,
null
);
PC.Close();
PC1.Close();
}
}
}
}
}
示例12: TestMergeTableTiming
public void TestMergeTableTiming(int mergeMax, int size)
{
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = Process.GetCurrentProcess().ProcessName;
Console.WriteLine("TESTING: page max({0}) record count({1})", mergeMax, size);
var basename = "RazorDbTests.IndexingTests";
var rand = new Random((int)DateTime.Now.Ticks);
var indexHash = new Dictionary<ByteArray, byte[]>();
var itemKeyLen = 35;
var kvsName = string.Format("MergeTableTiming_{0}_{1}", mergeMax, DateTime.Now.Ticks);
var sw = new Stopwatch();
sw.Start();
using (var testKVS = new KeyValueStore(Path.Combine(basename, kvsName))) {
// add a bunch of values that look like indexes
for (int r = 0; r < size; r++) {
var indexLen = (int)(DateTime.Now.Ticks % 60) + 50;
var indexKeyBytes = dataset[r];
var valuekeyBytes = indexKeyBytes.Skip(indexKeyBytes.Length - itemKeyLen).ToArray();
testKVS.Set(indexKeyBytes, valuekeyBytes); // old style index
indexHash.Add(new ByteArray(valuekeyBytes), indexKeyBytes);
}
TableManager.RunTableMergePass(testKVS);
}
sw.Stop();
var memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024);
Console.WriteLine("Total processing time: {0} entries {1} mergeSz {2} MEMORY: {3}", size, mergeMax, sw.Elapsed.ToString(), memsize);
Console.WriteLine();
PC.Close();
PC.Dispose();
}
示例13: Process
private void Process()
{
while (!finalizeService)
{
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Processor";
PC.CounterName = "% Processor Time";
PC.InstanceName = "_Total";
PC.ReadOnly = true;
var value = PC.NextValue();
Thread.Sleep(1000);
value = PC.NextValue();
PC.Close();
PC.Dispose();
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
var ramValue = ramCounter.NextValue();
if (ramValue < MinRAMAvailable)
{
SendAlertMessage(AlertType.RAM_ALERT, value,Convert.ToInt64(ramValue));
}
if (value > MaxCPUUsage)
{
totalHits = totalHits + 1;
if (totalHits == Period)
{
SendAlertMessage(AlertType.PROCESS_ALERT, value, Convert.ToInt64(ramValue));
totalHits = 0;
}
}
else
{
totalHits = 0;
}
}
eventLog.WriteEntry(ServiceName + " stoped.");
}
示例14: ReleasePerformanceCounter
/// <summary>
/// Releases the performance counter.
/// </summary>
/// <param name="performanceCounter">The performance counter.</param>
private static void ReleasePerformanceCounter(ref PerformanceCounter performanceCounter)
{
if (performanceCounter != null)
{
performanceCounter.Close();
performanceCounter = null;
}
}
示例15: AdjustConcurrentScanCount_Tick
private void AdjustConcurrentScanCount_Tick(object sender, EventArgs e)
{
const int cpuRequiredPerProcess = 20; // actual is closer to 20
const int cpuBuffer = 20; // always save 30% CPU for random spikes
const int mBytesRequiredPerProcess = 40; // actual is closer to 60
const int mBytesBuffer = 400; // always save 500mb of RAM for random spikes
var cpuCounter = new PerformanceCounter
{CategoryName = "Processor", CounterName = "% Processor Time", InstanceName = "_Total"};
var ramCounter = new PerformanceCounter {CategoryName = "Memory", CounterName = "Available MBytes"};
cpuCounter.NextValue(); // for some reason this returns 0 on the first call
ramCounter.NextValue();
Thread.Sleep(500);
int freeCycles = 100 - Convert.ToInt32(cpuCounter.NextValue()) - cpuBuffer;
long freeMBytes = (long)ramCounter.NextValue() - mBytesBuffer;
int allowedViaCPUCalc = (freeCycles + cpuRequiredPerProcess * HostWorker.ScanProcessList.Count) / cpuRequiredPerProcess;
int allowedViaRAMCalc = Convert.ToInt32((freeMBytes + mBytesRequiredPerProcess * HostWorker.ScanProcessList.Count) / mBytesRequiredPerProcess);
HostWorker.AllowedConcurrentScanCount = Math.Min(allowedViaCPUCalc, allowedViaRAMCalc);
cpuCounter.Close();
ramCounter.Close();
}