如何获取phantomJS浏览器的cpu利用率数据?

时间:2016-10-24 14:54:38

标签: c# phantomjs nunit

public static readonly PerformanceCounter theCPUCounter =
        new PerformanceCounter("Processor", "% Processor Time", "_Total");

    public static readonly PerformanceCounter theMemCounter =
        new PerformanceCounter("Memory", "Available MBytes");

    public  static readonly PerformanceCounter theCPUCounterPhantomJS =
        new PerformanceCounter("Processor", "% Processor Time", Process.GetProcessesByName("phantomjs").ToString());  

    public static void getCurrentCpuUsage()
    {
        Console.WriteLine(theCPUCounter.NextValue() + " %");
    }

    public static void getAvailableRAM()
    {
        Console.WriteLine(theMemCounter.NextValue() + " MB");           
    }

    public static void getCurrentCpuUsagePhantomJS()
    {
        Console.WriteLine(theCPUCounterPhantomJS.NextValue() + " %");
    }

我想要PhantomJS浏览器的cpu利用率数据。这是我正在使用的代码。我只想知道我可以输入什么参数而不是 Process.GetProcessesByName(" phantomjs")。ToString()。我尝试了很多方法,但它失败并给了我异常 System.InvalidOperationException:Instance' System.Diagnostics.Process []'在指定的类别中不存在。。该过程的名称是 phantomjs.exe enter image description here,显示在任务管理器中。请指教。

1 个答案:

答案 0 :(得分:0)

请参阅the docs - 这是您应该如何在您的情况下实例化性能计数器:

<ion-content  no-bounce>

  <div class="boxContainer" padding-top="">
    <div class="box">
      <ion-grid text-center>
        <ion-row>
          <ion-col width-33>
            <p class="walletTextParag">Cüzdanınız:</p>
          </ion-col>
        </ion-row>
        <ion-row>
          <ion-col width-33>
            <h1 class="walletText">{{ (profileData | async)?.wallet}} ₺</h1>
          </ion-col>
        </ion-row>
        <ion-row>
          <ion-col width-50>
            <button class="walletButton" ion-button="" icon-left color="color1" (click)="seePaymentsArchive()">
              <ion-icon name="ios-calendar"></ion-icon>
              Ödeme geçmişi
            </button>
          </ion-col>
        </ion-row>
      </ion-grid>
    </div>
  </div>
</ion-content>

Process.GetProcessesByName返回一个进程数组,因此ToString导致&#34; System.Diagnostics.Process []&#34;,这不是有效的实例名称,不在Processor类别下,而不是在流程类别下。