@Test
public void thisProcessCpuUsage() {

  mySeries = new LegacyCpuUsageDataSeries(
    new ProfilerClient(myGrpcChannel.getName()).getCpuClient(), ProfilersTestData.SESSION_DATA, false);
  int systemTime = (int)(0.6 * FakeCpuService.TOTAL_ELAPSED_TIME);
  int appTime = (int)(0.4 * FakeCpuService.TOTAL_ELAPSED_TIME);
  myService.setSystemTimeMs(systemTime);
  myService.setAppTimeMs(appTime);
  List<SeriesData<Long>> seriesData = mySeries.getDataForRange(ANY_RANGE);
  assertEquals(1, seriesData.size());
  SeriesData<Long> appUsageData = seriesData.get(0);
  assertNotNull(appUsageData);
  assertEquals(40, (long)appUsageData.value); // 40% of total elapsed time
  systemTime = (int)(0.6 * FakeCpuService.TOTAL_ELAPSED_TIME);
  appTime = (int)(0.8 * FakeCpuService.TOTAL_ELAPSED_TIME);
  myService.setSystemTimeMs(systemTime);
  myService.setAppTimeMs(appTime);
  seriesData = mySeries.getDataForRange(ANY_RANGE);
  assertEquals(1, seriesData.size());
  appUsageData = seriesData.get(0);
  assertNotNull(appUsageData);
  // App usage shouldn't be greater than system usage. If that happens, we cap the value to
  // the system total usage.
  assertEquals(systemTime, (long)appUsageData.value);
  appTime = (int)(-0.2 * FakeCpuService.TOTAL_ELAPSED_TIME);
  myService.setAppTimeMs(appTime);
  seriesData = mySeries.getDataForRange(ANY_RANGE);
  assertEquals(1, seriesData.size());
  appUsageData = seriesData.get(0);
  assertNotNull(appUsageData);
  // App usage shouldn't be less than 0%. If that happens, we cap the value to 0%.
  assertEquals(0, (long)appUsageData.value);
}