Example #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()
Example #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()
Example #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()
Example #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()
Example #5
0
    add_trace_source_options(cmd_convert_dump)
    cmd_convert_dump.add_argument("-f",
                                  "--dumpfile",
                                  action="store",
                                  help="Trace dump file",
                                  default="buffers")
    cmd_convert_dump.set_defaults(func=convert_dump, paginate=False)

    cmd_download_dump = subparsers.add_parser(
        "download",
        help="download trace dump file (REST)",
        description="""
                                             Downloads a trace dump via REST Api
                                             """)
    add_trace_source_options(cmd_download_dump)
    Client.add_arguments(cmd_download_dump, use_full_url=True)
    cmd_download_dump.set_defaults(func=download_dump, paginate=False)

    args = parser.parse_args()

    if getattr(args, 'paginate', False):
        less_process = subprocess.Popen(['less', '-FX'],
                                        stdin=subprocess.PIPE,
                                        text=True)
        sys.stdout = less_process.stdin
    else:
        less_process = None

    try:
        args.func(args)
    except InvalidArgumentsException as e:
Example #6
0
File: top.py Project: ayush1794/osv
import collections

from osv.client import Client

try:
    import curses
    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()
Example #7
0
File: top.py Project: mohankku/osv
import collections

from osv.client import Client

try:
    import curses
    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()
Example #8
0
    cmd_convert_dump = subparsers.add_parser("convert-dump", help="convert trace dump file (REST)"
                                             , description="""
                                             Converts trace dump acquired via REST Api to trace listing format
                                             """)
    add_trace_source_options(cmd_convert_dump)
    cmd_convert_dump.add_argument("-f", "--dumpfile", action="store",
                                  help="Trace dump file",
                                  default="buffers")
    cmd_convert_dump.set_defaults(func=convert_dump, paginate=False)

    cmd_download_dump = subparsers.add_parser("download", help="download trace dump file (REST)"
                                             , description="""
                                             Downloads a trace dump via REST Api
                                             """)
    add_trace_source_options(cmd_download_dump)
    Client.add_arguments(cmd_download_dump, use_full_url=True)
    cmd_download_dump.set_defaults(func=download_dump, paginate=False)


    args = parser.parse_args()

    if getattr(args, 'paginate', False):
        less_process = subprocess.Popen(['less', '-FX'], stdin=subprocess.PIPE)
        sys.stdout = less_process.stdin
    else:
        less_process = None

    try:
        args.func(args)
    except InvalidArgumentsException as e:
        print "Invalid arguments:", e.message