Skip to content

Instantly share code, notes, and snippets.

@robertonscjr
Created June 27, 2020 17:25
Show Gist options
  • Save robertonscjr/28f3a1912fe434c91b2e6d80c8b6e5b0 to your computer and use it in GitHub Desktop.
Save robertonscjr/28f3a1912fe434c91b2e6d80c8b6e5b0 to your computer and use it in GitHub Desktop.

Revisions

  1. robertonscjr created this gist Jun 27, 2020.
    54 changes: 54 additions & 0 deletions swap_monitoring.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    from flask import Flask, request
    import json
    import redis
    import subprocess
    import time


    app = Flask(__name__)

    redis_url = "0.0.0.0"
    redis_port = 6379
    rds = redis.StrictRedis(host=redis_url, port=redis_port, db=0)


    def monitor_swap_controller(req):
    req_json = req.json

    evicteds = []

    cmd = ('sudo cat /sys/module/isgx/parameters/sgx_nr_evicted')
    result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    stdin=subprocess.PIPE).communicate()

    last_evicted = float(result[0].rstrip()) * 4 / 1024

    while(rds.exists("time_queue") == 0):
    cmd = ('sudo cat /sys/module/isgx/parameters/sgx_nr_evicted')

    result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    stdin=subprocess.PIPE).communicate()

    current_time = str(time.time())

    evicted = float(result[0].rstrip()) * 4 / 1024
    current_evicted = str(evicted - last_evicted)
    last_evicted = evicted

    evicteds.append((float(current_evicted), current_time))

    collect_period = 0.1
    time.sleep(collect_period)

    return json.dumps(evicteds)


    @app.route('/monitor/swap', methods=["POST"])
    def monitor_swap_api():
    return monitor_swap_controller(request)


    if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7654)