获取当前计算机所有性能计数器

来源:互联网 发布:java 接口变量 编辑:程序博客网 时间:2024/04/30 11:34

获取本机所有计数器项目下面所有的实例,和注册的计数器,并输出到文件。

下面是代码。

    Public Sub GetInf(Optional outputFile As String = "D:\pctext.txt")        Dim f = File.Create(outputFile)        Dim tw As New StreamWriter(f)        For Each item As PerformanceCounterCategory In PerformanceCounterCategory.GetCategories()            tw.WriteLine($"■■■■■■■■■■■■:{item.CategoryName.ToString()}")            Dim insts() As String = item.GetInstanceNames()            tw.WriteLine("♦♦♦:本机实例")            If insts.Length > 0 Then                For Each i In insts                    tw.WriteLine($"|:{i}")                Next            Else                tw.WriteLine("♦:没有命名本机实例。")            End If            tw.WriteLine("♦♦♦:本机计数器")            For Each ctor In item.GetCounters(If(insts.Length > 0, insts(0), ""))                tw.WriteLine($"|:{ctor.CounterName}")            Next            tw.WriteLine("========================================")        Next        tw.Flush()        f.Close()        MsgBox("已完成。")    End Sub


0 0
原创粉丝点击