예제 #1
0
def watch(conf, package, interval, serialno, output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    m = airtest.Monitor('android://'+serialno, package)

    outfd = None
    if output_file:
        outfd = open(output_file, 'wb')
        wr = csv.writer(outfd)
        
    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s'*len(items)
    # if syscpu:
    #     format += '%-12s'*2
    #     items += ['SYSAVGCPU', 'SYSALLCPU']

    print format % tuple(items)
    if outfd:
        wr.writerow(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))


        #cpu = app.dev.cpuinfo(package)
        values.append(str(m.cpu()))

        mem = m.memory()
        strvals = values[:]
        for item in mem_items:
            v = int(mem.get(item, 0))*1024
            # if human_readable:
            v_str = humanize.naturalsize(int(v))
            # else:
            # v_str = v
            strvals.append(v_str)
            values.append(round(v/1024.0/1024, 2))

        # if syscpu:
        #     syscpus = m.sys_cpu(True)
        #     cpustr = '|'.join([str(round(v, 2)) for v in syscpus])
        #     sysavg = sum(syscpus)/len(syscpus)
        #     values += [(round(sysavg, 2)), cpustr]
        #     strvals += [str(round(sysavg, 2)), cpustr]

        print format % tuple(strvals)
        if outfd:
            wr.writerow(values)
            # outfd.write((format + '\n') % tuple(values))
            # outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
예제 #2
0
def uninstall(conf, serialno, apk):
    if not apk:
        apk = _get_apk(conf, cache=True)
    pkg, act = androaxml.parse_apk(apk)
    args = ['adb']
    if serialno:
        args.extend(['-s', serialno])
    args += ['uninstall', pkg]
    _run(*args)
예제 #3
0
def uninstall(conf, serialno, apk):
    if not apk:
        apk = _get_apk(conf, cache=True)
    pkg, act = androaxml.parse_apk(apk)
    args = ['adb']
    if serialno:
        args.extend(['-s', serialno])
    args += ['uninstall', pkg]
    _run(*args)
예제 #4
0
def watch(conf, package, interval, serialno, output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    m = airtest.Monitor('android://' + serialno, package)

    outfd = None
    if output_file:
        outfd = open(output_file, 'wb')
        wr = csv.writer(outfd)

    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s' * len(items)
    # if syscpu:
    #     format += '%-12s'*2
    #     items += ['SYSAVGCPU', 'SYSALLCPU']

    print format % tuple(items)
    if outfd:
        wr.writerow(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))

        #cpu = app.dev.cpuinfo(package)
        values.append(str(m.cpu()))

        mem = m.memory()
        strvals = values[:]
        for item in mem_items:
            v = int(mem.get(item, 0)) * 1024
            # if human_readable:
            v_str = humanize.naturalsize(int(v))
            # else:
            # v_str = v
            strvals.append(v_str)
            values.append(round(v / 1024.0 / 1024, 2))

        # if syscpu:
        #     syscpus = m.sys_cpu(True)
        #     cpustr = '|'.join([str(round(v, 2)) for v in syscpus])
        #     sysavg = sum(syscpus)/len(syscpus)
        #     values += [(round(sysavg, 2)), cpustr]
        #     strvals += [str(round(sysavg, 2)), cpustr]

        print format % tuple(strvals)
        if outfd:
            wr.writerow(values)
            # outfd.write((format + '\n') % tuple(values))
            # outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
예제 #5
0
def watch(conf, package, interval, serialno, human_readable, syscpu,
          output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    # app = airtest.connect(serialno, device=airtest.ANDROID, monitor=False)
    airtest.connect('android://' + serialno)
    m = airtest.Monitor('android://' + serialno, package)

    outfd = None
    if output_file:
        outfd = open(output_file, 'w')

    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s' * len(items)
    if syscpu:
        format += '%-12s' * 2
        items += ['SYSAVGCPU', 'SYSALLCPU']

    print format % tuple(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))

        #cpu = app.dev.cpuinfo(package)
        values.append(str(m.cpu()))

        mem = m.memory()  #app.dev.meminfo(package)
        for item in mem_items:
            v = int(mem.get(item, 0)) * 1024

            if human_readable:
                v = humanize.naturalsize(int(v))
            values.append(str(v))

        if syscpu:
            syscpus = m.sys_cpu(True)
            cpustr = '|'.join([str(round(v, 2)) for v in syscpus])
            sysavg = sum(syscpus) / len(syscpus)
            values += [str(round(sysavg, 2)), cpustr]

        print format % tuple(values)
        if outfd:
            outfd.write((format + '\n') % tuple(values))
            outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
예제 #6
0
def install(no_start, conf, serialno, apk):
    apk = _get_apk(conf)

    adbargs = ['adb']
    if serialno:
        adbargs.extend(['-s', serialno])
    args = adbargs + ['install', '-r', apk]
    # install app
    _run(*args)

    if no_start:
        return
    pkg, act = androaxml.parse_apk(apk)
    args = adbargs + ['shell', 'am', 'start', '-n', pkg+'/'+act]
    _run(*args)
예제 #7
0
def install(no_start, conf, serialno, apk):
    if not apk:
        apk = _get_apk(conf)
    adbargs = ['adb']
    if serialno:
        adbargs.extend(['-s', serialno])
    args = adbargs + ['install', '-r', apk]
    # install app
    _run(*args)

    if no_start:
        return
    pkg, act = androaxml.parse_apk(apk)
    args = adbargs + ['shell', 'am', 'start', '-n', pkg + '/' + act]
    _run(*args)
예제 #8
0
def watch(conf, package, interval, serialno, human_readable, output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    app = airtest.connect(phoneno=serialno, device=airtest.ANDROID, monitor=False)

    # print app.dev.getdevinfo()
    outfd = None
    if output_file:
        outfd = open(output_file, 'w')

    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s'*len(items)
    print format % tuple(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))
        
        cpu = app.dev.getCpu(package)
        values.append(str(cpu))

        mem = app.dev.getMem(package)
        for item in mem_items:
            v = int(mem.get(item))*1024
            if human_readable:
                v = humanize.naturalsize(int(v))
            values.append(str(v))

        print format % tuple(values)
        if outfd:
            outfd.write((format + '\n') % tuple(values))
            outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
예제 #9
0
def inspect(apkfile):
    pkg, act = androaxml.parse_apk(apkfile)
    click.echo('Package Name: "%s"' % pkg)
    click.echo('Activity: "%s"' % act)
예제 #10
0
def inspect(apkfile):
    pkg, act = androaxml.parse_apk(apkfile)
    click.echo('Package Name: "%s"' % pkg)
    click.echo('Activity: "%s"' % act)