def get_cpu_usage(cr):
     time.sleep(STABILIZATION_DURATION)
     cpu_usage_start = site_utils.get_cpu_usage()
     time.sleep(MEASUREMENT_DURATION)
     cpu_usage_end = site_utils.get_cpu_usage()
     return site_utils.compute_active_cpu_time(cpu_usage_start,
                                               cpu_usage_end) * 100
Beispiel #2
0
    def compute_active_cpu_time(self, cpu_usage_start, cpu_usage_end):
        """Computes the fraction of CPU time spent non-idling.

        This function should be invoked using before/after values from calls to
        get_cpu_usage().
        """
        return site_utils.compute_active_cpu_time(cpu_usage_start,
                                                  cpu_usage_end)
    def get_cpu_usage(self):
        """Computes current cpu usage in percentage.

        @returns percentage cpu used as a float.

        """
        cpu_usage_start = site_utils.get_cpu_usage()
        time.sleep(MEASUREMENT_DURATION)
        cpu_usage_end = site_utils.get_cpu_usage()
        return site_utils.compute_active_cpu_time(cpu_usage_start,
                                                  cpu_usage_end) * 100
    def test_cpu_usage(self):
        """
        Runs the video cpu usage test.

        @param local_path: the path to the video file.

        @returns a dictionary that contains the test result.
        """
        cpu_usage_start = site_utils.get_cpu_usage()
        time.sleep(MEASUREMENT_DURATION)
        cpu_usage_end = site_utils.get_cpu_usage()
        return site_utils.compute_active_cpu_time(cpu_usage_start,
                                                  cpu_usage_end) * 100
    def _get_cpu_usage(self):
        """Compute percent CPU in active use over the sample interval.

        Note: This method introduces a sleep period into the test, equal to
        90% of the sample interval.

        @returns float of percent active use of CPU.
        """
        # Time between measurements is ~90% of the sample interval.
        measurement_time_delta = SAMPLE_INTERVAL * 0.90
        cpu_usage_start = site_utils.get_cpu_usage()
        time.sleep(measurement_time_delta)
        cpu_usage_end = site_utils.get_cpu_usage()
        return site_utils.compute_active_cpu_time(cpu_usage_start,
                                                  cpu_usage_end) * 100