客户端性能测试通过performanceCounter监控客户端性能指标

来源:互联网 发布:韫而知之的意思 编辑:程序博客网 时间:2024/05/18 10:22

         PerformanceCounter PTCounter = new PerformanceCounter("Process",
                                        "% Processor Time",
                                         "AliIM");
            logfile("% Processor Time:" + PTCounter.NextValue().ToString());
            //内存
            PerformanceCounter WSCounter = new PerformanceCounter("Process",
                                                                    "Working Set",
                                                                     "AliIM");
            logfile("Working Set:" + ((double)WSCounter.NextValue() / 1024).ToString());

            //内存最高值
            PerformanceCounter MemeryCounter = new PerformanceCounter("Process",
                                                                    "Working Set Peak",
                                                                     "AliIM");
            logfile("Working Set Peak:" + ((double)MemeryCounter.NextValue() / 1024).ToString());


            //虚拟内存
            PerformanceCounter PBCounter = new PerformanceCounter("Process",
                                                              "Private Bytes",
                                                               "AliIM");
            logfile("Private Bytes:" + ((double)PBCounter.NextValue() / 1024).ToString());

            //句柄数
            PerformanceCounter HCCounter = new PerformanceCounter("Process",
                                                  "Handle Count",
                                                   "AliIM");
            logfile("Handle Count:" + HCCounter.NextValue() .ToString());

            //线程数Thread Count
            PerformanceCounter TCCounter = new PerformanceCounter("Process",
                                      "Thread Count",
                                       "AliIM");
            logfile("Thread Count:" + TCCounter.NextValue() .ToString());

 

//补充得到GDI OBJECTS

            Process process;
            process = System.Diagnostics.Process.GetProcessesByName("AliIM")[0];
           
            logfile("GDI Objects Count:" + GetGuiResources(process.Handle, 0));

 

        [DllImport("User32")]

        extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);