Esempio n. 1
0
def download_dump(args):
    if os.path.exists(args.tracefile):
        os.remove(args.tracefile)
        assert (not os.path.exists(args.tracefile))

    file = args.tracefile
    client = Client(args)
    url = client.get_url() + "/trace/buffers"

    print("Downloading %s -> %s" % (url, file))

    r = requests.get(url, stream=True, **client.get_request_kwargs())
    size = int(r.headers['content-length'])
    current = 0

    with open(file, 'wb') as out_file:
        for chunk in r.iter_content(8192):
            out_file.write(chunk)
            current += len(chunk)
            sys.stdout.write("[{0:8d} / {1:8d} k] {3} {2:.2f}%\r".format(
                current // 1024, size // 1024, 100.0 * current // size,
                ('=' * 32 * (current // size)) + '>'))
            if current >= size:
                sys.stdout.write("\n")
            sys.stdout.flush()
Esempio n. 2
0
def download_dump(args) :
    out = None;
    if args.dumpfile == None:
        if not args.no_convert:
            out = tempfile.NamedTemporaryFile()
            args.dumpfile = out.name
        else:
            args.dumpfile = "buffers"
    if out == None:
        out = open(args.dumpfile, "wb")

    try:
        client = Client(args)
        url = client.get_url() + "/trace/buffers"

        print "Downloading %s -> %s" % (url, out.name)

        r = requests.get(url, stream=True, **client.get_request_kwargs())
        size = int(r.headers['content-length'])
        current = 0

        with open(out.name, 'w') as out_file:
            for chunk in r.iter_content(8192):
                out_file.write(chunk)
                current += len(chunk)
                sys.stdout.write("[{0:8d} / {1:8d} k] {3} {2:.2f}%\r".format(current/1024, size/1024, 100.0*current/size, ('='*32*(current/size)) + '>'))
                if current >= size:
                    sys.stdout.write("\n")
                sys.stdout.flush()

        if not args.no_convert:
            convert_dump(args)
    finally:
        out.close()
Esempio n. 3
0
def download_dump(args) :
    if os.path.exists(args.tracefile):
        os.remove(args.tracefile)
        assert(not os.path.exists(args.tracefile))

    file = args.tracefile
    client = Client(args)
    url = client.get_url() + "/trace/buffers"

    print "Downloading %s -> %s" % (url, file)

    r = requests.get(url, stream=True, **client.get_request_kwargs())
    size = int(r.headers['content-length'])
    current = 0

    with open(file, 'wb') as out_file:
        for chunk in r.iter_content(8192):
            out_file.write(chunk)
            current += len(chunk)
            sys.stdout.write("[{0:8d} / {1:8d} k] {3} {2:.2f}%\r".format(current/1024, size/1024, 100.0*current/size, ('='*32*(current/size)) + '>'))
            if current >= size:
                sys.stdout.write("\n")
            sys.stdout.flush()
Esempio n. 4
0
def download_dump(args):
    out = None
    if args.dumpfile == None:
        if not args.no_convert:
            out = tempfile.NamedTemporaryFile()
            args.dumpfile = out.name
        else:
            args.dumpfile = "buffers"
    if out == None:
        out = open(args.dumpfile, "wb")

    try:
        client = Client(args)
        url = client.get_url() + "/trace/buffers"

        print "Downloading %s -> %s" % (url, out.name)

        r = requests.get(url, stream=True, **client.get_request_kwargs())
        size = int(r.headers['content-length'])
        current = 0

        with open(out.name, 'w') as out_file:
            for chunk in r.iter_content(8192):
                out_file.write(chunk)
                current += len(chunk)
                sys.stdout.write("[{0:8d} / {1:8d} k] {3} {2:.2f}%\r".format(
                    current / 1024, size / 1024, 100.0 * current / size,
                    ('=' * 32 * (current / size)) + '>'))
                if current >= size:
                    sys.stdout.write("\n")
                sys.stdout.flush()

        if not args.no_convert:
            convert_dump(args)
    finally:
        out.close()
Esempio n. 5
0
File: top.py Progetto: ayush1794/osv
    curses.setupterm()
    clear = curses.tigetstr('clear').decode()
except:
    clear = '\033[H\033[2J'

parser = argparse.ArgumentParser(description="""
    Connects to a running OSv guest through the HTTP API and periodically displays
    the list of threads getting most CPU time, similarly to the Linux top(1)
    command.""")
Client.add_arguments(parser)

args = parser.parse_args()
client = Client(args)

url = client.get_url() + "/os/threads"
ssl_kwargs = client.get_request_kwargs()

period = 2.0  # How many seconds between refreshes

prevtime = collections.defaultdict(int)
cpu = dict()
name = dict()
timems = 0
while True:
    start_refresh = time.time()
    result = requests.get(url, **ssl_kwargs).json()
    print(clear, end='')
    newtimems = result['time_ms']

    print("%d threads " % (len(result['list'])), end='')
    diff = dict()
Esempio n. 6
0
File: top.py Progetto: mohankku/osv
    curses.setupterm()
    clear = curses.tigetstr('clear').decode()
except:
    clear = '\033[H\033[2J'

parser = argparse.ArgumentParser(description="""
    Connects to a running OSv guest through the HTTP API and periodically displays
    the list of threads getting most CPU time, similarly to the Linux top(1)
    command.""")
Client.add_arguments(parser)

args = parser.parse_args()
client = Client(args)

url = client.get_url() + "/os/threads"
ssl_kwargs = client.get_request_kwargs()

period = 2.0  # How many seconds between refreshes

prevtime = collections.defaultdict(int)
cpu = dict()
name = dict()
timems = 0
while True:
    start_refresh = time.time()
    result = requests.get(url, **ssl_kwargs).json()
    print(clear, end='')
    newtimems = result['time_ms']

    print("%d threads " % (len(result['list'])), end='')
    diff = dict()