def test_cpu_usage_for_process_calculates_result(self):
     """
     cputime_for_process correctly calculates the CPU percentage for
     a process by dividing the total cputime by the total wallclock
     time across all the samples.
     """
     process_name = 'test-process'
     results = [
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': process_name,
             'value': 10,
             'wallclock': 60
         },
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': process_name,
             'value': 30,
             'wallclock': 100
         },
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     # Total CPU time: 40
     # Total wallclock time: 160
     self.assertEqual(cputime_result, 0.25)
Example #2
0
 def test_cpu_usage_for_process_calculates_result(self):
     """
     cputime_for_process correctly calculates the CPU percentage for
     a process by dividing the total cputime by the total wallclock
     time across all the samples.
     """
     process_name = 'test-process'
     results = [
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': process_name,
             'value': 10,
             'wallclock': 60
         },
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': process_name,
             'value': 30,
             'wallclock': 100
         },
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     # Total CPU time: 40
     # Total wallclock time: 160
     self.assertEqual(cputime_result, 0.25)
Example #3
0
 def test_cpu_usage_for_process_no_matching_results(self):
     """
     cputime_for_process only considers results which have the
     'cputime' metric type and match the specified process name.
     None is returned if no results match.
     """
     process_name = "test-process"
     results = [
         {"metric": {"type": "wallclock"}, "process": process_name},
         {"metric": {"type": "cputime"}, "process": "another-process"},
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     self.assertEqual(cputime_result, None)
Example #4
0
 def test_cpu_usage_for_process_calculates_result(self):
     """
     cputime_for_process correctly calculates the CPU percentage for
     a process by dividing the total cputime by the total wallclock
     time across all the samples.
     """
     process_name = "test-process"
     results = [
         {"metric": {"type": "cputime"}, "process": process_name, "value": 10, "wallclock": 60},
         {"metric": {"type": "cputime"}, "process": process_name, "value": 30, "wallclock": 100},
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     # Total CPU time: 40
     # Total wallclock time: 160
     self.assertEqual(cputime_result, 0.25)
 def test_cpu_usage_for_process_no_matching_results(self):
     """
     cputime_for_process only considers results which have the
     'cputime' metric type and match the specified process name.
     None is returned if no results match.
     """
     process_name = 'test-process'
     results = [
         {
             'metric': {
                 'type': 'wallclock'
             },
             'process': process_name
         },
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': 'another-process'
         },
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     self.assertEqual(cputime_result, None)
Example #6
0
 def test_cpu_usage_for_process_no_matching_results(self):
     """
     cputime_for_process only considers results which have the
     'cputime' metric type and match the specified process name.
     None is returned if no results match.
     """
     process_name = 'test-process'
     results = [
         {
             'metric': {
                 'type': 'wallclock'
             },
             'process': process_name
         },
         {
             'metric': {
                 'type': 'cputime'
             },
             'process': 'another-process'
         },
     ]
     cputime_result = cpu_usage_for_process(results, process_name)
     self.assertEqual(cputime_result, None)