def _assert_polled_metrics_equal(self,
                                  metrics,
                                  cpu_metric_value,
                                  memory_metric_value,
                                  max_memory_metric_value,
                                  proc_stat_memory_usage_value,
                                  pids=None):
     for metric in metrics:
         self.assertIn(metric.category, ["Process", "Memory"])
         if metric.category == "Process":
             self.assertEqual(metric.counter, "% Processor Time")
             self.assertEqual(metric.value, cpu_metric_value)
         if metric.category == "Memory":
             self.assertIn(metric.counter, [
                 "Total Memory Usage", "Max Memory Usage",
                 "Memory Used by Process"
             ])
             if metric.counter == "Total Memory Usage":
                 self.assertEqual(metric.value, memory_metric_value)
             elif metric.counter == "Max Memory Usage":
                 self.assertEqual(metric.value, max_memory_metric_value)
             elif metric.counter == "Memory Used by Process":
                 if pids:
                     processes_instances = [
                         CGroupsTelemetry.get_process_info_summary(pid)
                         for pid in pids
                     ]
                 else:
                     processes_instances = [
                         CGroupsTelemetry.get_process_info_summary(pid)
                         for pid in TestCGroupsTelemetry.TestProcessIds
                     ]
                 self.assertIn(metric.instance, processes_instances)
                 self.assertEqual(metric.value,
                                  proc_stat_memory_usage_value)
    def _assert_calculated_resource_metrics_equal(self,
                                                  cpu_usage,
                                                  memory_usage,
                                                  max_memory_usage,
                                                  memory_statm_memory_usage,
                                                  proc_ids=None):
        if not proc_ids:
            proc_ids = TestCGroupsTelemetry.TestProcessIds

        processes_instances = [
            CGroupsTelemetry.get_process_info_summary(pid) for pid in proc_ids
        ]
        for _, cgroup_metric in CGroupsTelemetry._cgroup_metrics.items():
            self.assertListEqual(cgroup_metric.get_memory_metrics()._data,
                                 memory_usage)
            self.assertListEqual(cgroup_metric.get_max_memory_metrics()._data,
                                 max_memory_usage)
            self.assertListEqual(cgroup_metric.get_cpu_metrics()._data,
                                 cpu_usage)
            for kv_pair in cgroup_metric.get_proc_statm_memory_metrics():
                self.assertIn(kv_pair.pid_name_cmdline, processes_instances)
                self.assertListEqual(kv_pair.resource_metric._data,
                                     memory_statm_memory_usage)