Ejemplo n.º 1
0
            print("CPU target load out of the range [0,1]")
            sys.exit(1)
        if options['duration'] < 0:
            print("Invalid duration")
            sys.exit(1)
        if options['plot'] != 0 and options['plot'] != 1:
            print("plot can be enabled 1 or disabled 0")
            sys.exit(1)
        if options['cpu_core'] >= multiprocessing.cpu_count():
            print("You have only %d cores on your machine" %
                  (multiprocessing.cpu_count()))
            sys.exit(1)

    monitor = MonitorThread(options['cpu_core'], 0.1)
    monitor.start()

    control = ControllerThread(0.1)
    control.start()
    control.setCpuTarget(options['cpuLoad'])

    actuator = closedLoopActuator(control, monitor, options['duration'],
                                  options['cpu_core'], options['cpuLoad'],
                                  options['plot'])
    actuator.run()
    actuator.close()

    monitor.running = 0
    control.running = 0
    monitor.join()
    control.join()
Ejemplo n.º 2
0
        stepPeriod = 4

        control = ControllerThread(0.1)
        monitor = MonitorThread(0, 0.1)
        actuator = closedLoopActuator(control, monitor, len(cpuSequence) * stepPeriod, 0, 1, dynamics_plot_online)

        monitor.start()
        control.start()
        actuator.run_sequence(cpuSequence)
        
        actuator.close()
        monitor.running = 0
        control.running = 0
        dynamics =  monitor.getDynamics()
       
        monitor.join()
        control.join()
        
        stepPeriod = 4
                
        with open('pid_data', 'w') as outfile:
            json.dump(dynamics, outfile)
    else:
        with open('pid_data', 'r') as outfile:
            dynamics = json.load(outfile)

    plt.figure()
    fig, ax1 = plt.subplots()
    ax1.set_ylabel('CPU Load (%)', color='b')
    ax1.plot(dynamics['time'], dynamics['cpu'], 'b-')
    ax1.set_xlabel('Time [ms]')