def cpu_percent(interval=<NUM_LIT:0.1>, percpu=False):
global _last_cpu_times<EOL>global _last_per_cpu_times<EOL>blocking = interval is not None and interval > <NUM_LIT:0.0><EOL>def calculate(t1, t2):<EOL><INDENT>t1_all = sum(t1)<EOL>t1_busy = t1_all - t1.idle<EOL>t2_all = sum(t2)<EOL>t2_busy = t2_all - t2.idle<EOL>if t2_busy <= t1_busy:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>busy_delta = t2_busy - t1_busy<EOL>all_delta = t2_all - t1_all<EOL>busy_perc = (busy_delta / all_delta) * <NUM_LIT:100><EOL>return round(busy_perc, <NUM_LIT:1>)<EOL><DEDENT>if not percpu:<EOL><INDENT>if blocking:<EOL><INDENT>t1 = cpu_times()<EOL>time.sleep(interval)<EOL><DEDENT>else:<EOL><INDENT>t1 = _last_cpu_times<EOL><DEDENT>_last_cpu_times = cpu_times()<EOL>return calculate(t1, _last_cpu_times)<EOL><DEDENT>else:<EOL><INDENT>ret = []<EOL>if blocking:<EOL><INDENT>tot1 = cpu_times(percpu=True)<EOL>time.sleep(interval)<EOL><DEDENT>else:<EOL><INDENT>tot1 = _last_per_cpu_times<EOL><DEDENT>_last_per_cpu_times = cpu_times(percpu=True)<EOL>for t1, t2 in zip(tot1, _last_per_cpu_times):<EOL><INDENT>ret.append(calculate(t1, t2))<EOL><DEDENT>return ret<EOL><DEDENT>
Return a float representing the current system-wide CPU
    utilization as a percentage.

    When interval is > 0.0 compares system CPU times elapsed before
    and after the interval (blocking).

    When interval is 0.0 or None compares system CPU times elapsed
    since last call or module import, returning immediately.
    In this case is recommended for accuracy that this function be
    called with at least 0.1 seconds between calls.

    When percpu is True returns a list of floats representing the
    utilization as a percentage for each CPU.
    First element of the list refers to first CPU, second element
    to second CPU and so on.
    The order of the list is consistent across calls.