# Path: misc/cpu.py
# CPU_PREFIX = '/sys/devices/system/cpu/'
# def save():
# def change(governor, freq=None):
# def available_freq():
# def min_freq():
# def max_freq():
# def dump():
# 
# Path: misc/buggers.py
# def silence():
#     def noise():


import argparse
import sys
import asyncio as aio
import os
import statistics
import uvloop
import psutil
from asyncio.subprocess import PIPE, STDOUT
from misc import cpu
from misc import buggers
def cpu_usage(p):
    return p.cpu_percent() + sum(c.cpu_percent() for c in p.children())


def connections(process):
    return len(
        set(c.fd for c in process.connections()) |
        set(c.fd for p in process.children() for c in p.connections()))


def memory(p):
    return p.memory_percent('uss') \
        + sum(c.memory_percent('uss') for c in p.children())


if __name__ == '__main__':
    buggers.silence()
    loop = uvloop.new_event_loop()

    argparser = argparse.ArgumentParser('do_wrk')
    argparser.add_argument('-s', dest='server', default='')
    argparser.add_argument('-e', dest='endpoint')
    argparser.add_argument('--pid', dest='pid', type=int)
    argparser.add_argument(
        '--no-cpu', dest='cpu_change', default=True,
        action='store_const', const=False)

    args = argparser.parse_args(sys.argv[1:])

    if args.cpu_change:

# Path: misc/cpu.py
# CPU_PREFIX = '/sys/devices/system/cpu/'
# def save():
# def change(governor, freq=None):
# def available_freq():
# def min_freq():
# def max_freq():
# def dump():
# 
# Path: misc/buggers.py
# def silence():
#     def noise():


# Path: do_wrk.py
import argparse
import sys
import asyncio as aio
import os
import statistics
import uvloop
import psutil
from asyncio.subprocess import PIPE, STDOUT
from misc import cpu
from misc import buggers

def cpu_usage(p):
    return p.cpu_percent() + sum(c.cpu_percent() for c in p.children())


def connections(process):
    return len(
        set(c.fd for c in process.connections()) |
        set(c.fd for p in process.children() for c in p.connections()))


def memory(p):
    return p.memory_percent('uss') \
        + sum(c.memory_percent('uss') for c in p.children())


if __name__ == '__main__':
    buggers.silence()
    loop = uvloop.new_event_loop()

    argparser = argparse.ArgumentParser('do_wrk')
    argparser.add_argument('-s', dest='server', default='')
    argparser.add_argument('-e', dest='endpoint')
    argparser.add_argument('--pid', dest='pid', type=int)
    argparser.add_argument(
        '--no-cpu', dest='cpu_change', default=True,
        action='store_const', const=False)

    args = argparser.parse_args(sys.argv[1:])

    if args.cpu_change:

        cpu.change('userspace', cpu.min_freq())