#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1008
Task: Write a Python function that monitors CPU usage percentage over 3 seconds using /proc/stat
Generated: 2026-02-12T16:48:34.341281
"""

import time

def read_cpu_usage():
    with open('/proc/stat', 'r') as f:
        line = f.readline()
    parts = line.strip().split()
    user = int(parts[1])
    nice = int(parts[2])
    system = int(parts[3])
    idle = int(parts[4])
    total_prev = user + nice + system + idle

    time.sleep(3)

    with open('/proc/stat', 'r') as f:
        line = f.readline()
    parts = line.strip().split()
    user = int(parts[1])
    nice = int(parts[2])
    system = int(parts[3])
    idle = int(parts[4])
    total_curr = user + nice + system + idle

    diff = total_curr - total_prev
    total_cpu_time = total_curr - total_prev
    cpu_usage_percent = (diff / total_cpu_time) * 100 if total_cpu_time != 0 else 0
    return cpu_usage_percent

if __name__ == '__main__':
    usage = read_cpu_usage()
    print(f"CPU Usage Percentage over 3 seconds: {usage:.2f}%")