def get_start_time(type):
    '''根据type的数值,选择进行back,home和冷启动的循环操作'''
    i = 0
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' + GetPath.start + '\\' + path +
             '.log')
    worksheet = workbook.add_sheet('MySheet3')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, 'TotalTime')
    worksheet.write(0, 2, 'ThisTime')
    worksheet.write(0, 3, 'WaitTime')
    while i < runtime:
        '''获取启动时间'''
        time.sleep(2)
        i = i + 1
        worksheet.write(i, 0, i, style)
        content = os.popen('adb shell am start -W ' +
                           Config().get_config()['pck_name'] + '/' +
                           Config().get_config()['activity']).read()
        TotalTime = re.search(r'(TotalTime:)\s(\d+)', content).group(2)
        print('TotalTime:' + TotalTime)
        ThisTime = re.search(r'(ThisTime:)\s(\d+)', content).group(2)
        print('ThisTime:' + ThisTime)
        WaitTime = re.search(r'(WaitTime:)\s(\d+)', content).group(2)
        print('WaitTime:' + WaitTime)
        worksheet.write(i, 1, TotalTime)
        worksheet.write(i, 2, ThisTime)
        worksheet.write(i, 3, WaitTime)
        time.sleep(3)
        os.popen('adb shell input keyevent ' + type)
        if type == "0":
            os.popen('adb shell am force-stop ' +
                     Config().get_config()['pck_name'])
        workbook.save(GetPath.start + '\\' + path + '.xlsx')
Beispiel #2
0
 def load(cls, fn: str, conf: dict):
     '''
         load prediction model from filename
     '''
     device = conf.get('DEVICE')
     self = torch.load(fn, map_location=device)
     Config.__init__(self, conf)
     return self
Beispiel #3
0
def oneTimeSetUp(request, browser):
    print("Running one time setUp")
    wd = Config(browser)
    driver = wd.getWebDriverInstance()
    if request.cls is not None:
        request.cls.driver = driver
    yield driver
    driver.quit()
    print("Running one time tearDown")
Beispiel #4
0
def get_mem_info():
    '''获取内存详情,每三秒读取一次内存值'''
    i = 0
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' +
             Config().get_config()['mem_back'] + path + '.log')
    # 数据写入Excel
    worksheet = workbook.add_sheet('MySheet2')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, 'Total')
    worksheet.write(0, 2, 'Java Heap')
    worksheet.write(0, 3, 'Native Heap')
    worksheet.write(0, 4, 'Stack')
    worksheet.write(0, 5, 'Graphics')
    worksheet.write(0, 6, 'Prinvate Other')
    worksheet.write(0, 7, 'System')
    worksheet.write(0, 8, 'TOTAL SWAP PSS')
    while i < runtime:
        '''进行back操作'''
        os.popen('adb shell am start -W ' + Config().get_config()['pck_name'] +
                 '/' + Config().get_config()['activity'])
        time.sleep(2)
        os.popen('adb shell input keyevent 4')
        i = i + 1
        worksheet.write(i, 0, i, style)
        out = os.popen("adb shell dumpsys meminfo " +
                       Config().get_config()['pck_name']).read()
        # 读取内存数值
        JavaHeap = get_code(out, 'Java Heap:')
        NativeHeap = get_code(out, "Native Heap:")
        Stack = get_code(out, "Stack:")
        Graphics = get_code(out, "Graphics:")
        PrinvateOther = get_code(out, "Private Other:")
        System = get_code(out, "System:")
        Total = get_code(out, "TOTAL:")
        TotalSwapPss = get_code(out, "TOTAL SWAP PSS:")
        print('TOTAL:' + Total)
        print('Java Heap:' + JavaHeap)
        print("Native Heap:" + NativeHeap)
        print("Stack:" + Stack)
        print("Graphics:" + Graphics)
        print("Private Other:" + PrinvateOther)
        print("System:" + System)
        print("TOTAL SWAP PSS:" + TotalSwapPss)
        worksheet.write(i, 1, Total)
        worksheet.write(i, 2, JavaHeap)
        worksheet.write(i, 3, NativeHeap)
        worksheet.write(i, 4, Stack)
        worksheet.write(i, 5, Graphics)
        worksheet.write(i, 6, PrinvateOther)
        worksheet.write(i, 7, System)
        worksheet.write(i, 8, TotalSwapPss)
        time.sleep(3)
        # 数据保存地址,以Excel表格保存
        workbook.save(Config().get_config()['mem_back'] + path + '.xls')
def get_cpu():
    j = 1
    i = 1
    processSum = 0
    processList = []
    worksheet = workbook.add_sheet('MySheet3')
    worksheet.write(0, 0, '时间')
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' +
             Config().get_config()['cpu_process'] + path + '.log')
    contents = os.popen("adb shell ps| findstr " +
                        Config().get_config()['pck_name']).readlines()
    rt = runtime * 20
    while i < rt:
        j = 0
        worksheet.write(i, 0, datetime.datetime.now(), style)
        while j < len(contents):
            if contents[j] == '\n':
                j = j + 1
            else:
                ''''遍历应用所有的进程和pid'''
                pid = contents[j].split()[1]
                #proc = contents[j].split()[8]
                try:
                    proc = re.search('(com.+)\n', contents[j]).group(1)
                except AttributeError:
                    continue
                '''遍历所有进程的CPU'''
                b = os.popen('adb shell dumpsys cpuinfo |findstr ' + pid)
                c = b.read()
                d = re.search(
                    r'([0-9]{0,1}[0-9]{0,1}[.][1-9]{0,1}\%|[0-9]{0,1}[0-9]{0,1}\%)\s\d{0,5}.',
                    c)
                try:
                    cpu = d.group(1)
                except AttributeError:
                    cpu = None
                    pass
                print(proc + '的CPU:' + str(cpu))
                j = j + 1
                name = str(pid) + proc
                if name not in processList:
                    processSum = processSum + 1
                    worksheet.write(0, processSum, name)
                    processList.append(name)
                processIndex = processList.index(name)
                if processIndex != -1:
                    worksheet.write(i, processIndex + 1, cpu)
            workbook.save(Config().get_config()['cpu_process'] + path +
                          '.xlsx')
        i = i + 1
        time.sleep(3)
    print('测试完毕。')
Beispiel #6
0
 def __init__(self, query_model: nn.Module, candidate_model: nn.Module, hidden_size, conf=None):
     nn.Module.__init__(self)
     Config.__init__(self, conf)
     # save model.
     self.query_model = query_model
     self.candidate_model = candidate_model
     # projection layer.
     self.proj = nn.Sequential(
         nn.Linear(3 * hidden_size, hidden_size, bias=self.USE_BIAS),
         activation[self.ACT_NAME](),
         nn.Linear(hidden_size, 2, bias=self.USE_BIAS)
     )
Beispiel #7
0
def get_cpu_info():
    '''获取cpu详情,每三秒读取一次cpu值'''
    i = 0
    # 判断应用进程是否存在
    try:
        content = os.popen("adb shell ps| findstr -e " + Config().get_config()['pck_name']).read()
        pid = content.split()[1]
    except IndexError as e:
        print('测试应用的进程不存在,正在开启应用···')
        # 如果不需要自动启动,可以把下面这行命令注释掉
        os.popen('adb shell am start -W ' + Config().get_config()['pck_name']
                 + '/' + Config().get_config()['activity'])
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' + GetPath.cpu_info + '\\' + path + '.log')
    # 数据写入Excel
    worksheet = workbook.add_sheet('MySheet2')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, 'Total')
    worksheet.write(0, 2, 'user')
    worksheet.write(0, 3, 'kernel')
    worksheet.write(0, 4, 'iowait')
    worksheet.write(0, 5, 'irq')
    worksheet.write(0, 6, 'softirq')
    rt = runtime * 20
    while i < rt:
        i = i + 1
        j = 0
        worksheet.write(i, 0, i, style)
        process = (os.popen('adb shell dumpsys cpuinfo '+ Config().get_config()['pck_name'])).readlines()
       # print(process)
        output = process[-1]
        if output == '\n':
            output = process[-2]
        print(output)
        Total = output.split()[0]
        user = get_code(output, 'user')
        kernel = get_code(output, 'kernel')
        iowait = get_code(output, 'iowait')
        irq = get_code(output, ' irq')
        softirq = get_code(output, 'softirq')
        print(Total, user, kernel, iowait, irq, softirq)
        time.sleep(3)
        worksheet.write(i, 1, Total)
        worksheet.write(i, 2, user)
        worksheet.write(i, 3, kernel)
        worksheet.write(i, 4, iowait)
        worksheet.write(i, 5, irq)
        worksheet.write(i, 6, softirq)
        time.sleep(3)
        # 数据保存地址,以Excel表格保存
        workbook.save(GetPath.cpu_info + '\\'+  path + '.xls')
def get_mem():
    '''查询多个进程的内存值'''
    j = 1
    i = 1
    processSum = 0
    processList = []
    worksheet = workbook.add_sheet('MySheet2')
    worksheet.write(0, 0, '次数')
    rt = runtime * 20
    while i < rt:
        '''每三秒获取一次内存值'''
        #print(contents)
        j = 0
        worksheet.write(i, 0, i, style)
        contents = os.popen("adb shell ps| findstr " +
                            Config().get_config()['pck_name']).readlines()
        while j < len(contents):
            if contents[j] == '\n':
                j = j + 1
            else:
                ''''遍历应用所有的进程和pid'''
                pid = contents[j].split()[1]
                #proc =contents[j].split()[8]
                try:
                    proc = re.search('(com.+)\n', contents[j]).group(1)
                except AttributeError:
                    continue
                '''Get all processes's memV'''
                b = os.popen('adb shell dumpsys meminfo ' + pid)
                c = b.read()
                d = re.search(r'(TOTAL)\s*(\d{0,8})', c)
                try:
                    mem = round(int(d.group(2)) / 1024, 2)
                except AttributeError:
                    mem = 0
                    pass
                print(proc + 'memValue:' + str(mem))
                j = j + 1
                name = str(pid) + proc
                if name not in processList:
                    processSum = processSum + 1
                    worksheet.write(0, processSum, name)
                    processList.append(name)
                processIndex = processList.index(name)
                if processIndex != -1:
                    worksheet.write(i, processIndex + 1, mem)
            workbook.save(Config().get_config()['mem_process'] + path +
                          '.xlsx')
        i = i + 1
        time.sleep(3)
    print('The test is finished!')
Beispiel #9
0
    def installer(self):
        '''Install all HackerMode packages and modules'''

        # Install the basics packages:
        for PACKAGE_NAME, SETUP in PACKAGES.items():
            for COMMANDS in SETUP[System.PLATFORME]:
                os.system(COMMANDS)

        # Install the basics python3 modules:
        for MODULES in PYHTON_MODULES.keys():
            if System.PLATFORME == 'linux':
                os.system(f'sudo pip3 install {MODULES}')
            elif System.PLATFORME == 'termux':
                os.system(f'pip install {MODULES}')

        # Install tools packages:
        if Config.get('actions', 'DEBUG', default=False):
            print('# In debug mode can"t run setup.sh')
            return
        tempPath = os.getcwd()
        run = f"python3 {os.path.abspath(os.path.join(HACKERMODE_PATH, 'base/bin/run.py'))}"
        TOOLS_PATH = os.path.abspath(os.path.join(HACKERMODE_PATH, 'base/tools'))
        try:
            for tool in os.listdir(TOOLS_PATH):
                os.chdir(os.path.join(TOOLS_PATH, tool))
                if os.path.isfile('setup.sh'):
                    os.system(f'{run} setup.sh')
        finally:
            os.chdir(tempPath)
Beispiel #10
0
def start_monkey():
    """获取相关参数,拼接monkey指令,执行指令"""
    # 多个输入框,添加缺省值不需要加default值
    title = "monkey测试"
    filenames = ["包名", 'throttle', 'event']
    filevalues = []
    filevalues = easygui.multenterbox(
        "请填写测试参数", title, filenames,
        ['com.excelliance.dualaid', '500', '10000'])
    pkg_name = filevalues[0]
    throttle = int(filevalues[1])
    event = int(filevalues[2])
    # log保存地址
    path_log = Config().get_config()['monkey_info']
    run_time = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
    # 检测usb连接
    if 'device' in os.popen('adb devices').read().split():
        print('设备已连接,开始monkey测试')
        # 把monkey命令分为三个部分
        adb_monkey = 'shell monkey -p %s --throttle %s --ignore-crashes --ignore-timeouts' \
                     ' --ignore-security-exceptions -v %s' % (pkg_name, throttle, event)
        monkey_log = path_log + "\\" + run_time + "monkey.log"
        cmd_monkey = 'adb %s > %s' % (adb_monkey, monkey_log)
        os.popen(cmd_monkey)

        # logcat日志
        logcat_log = path_log + "\\" + run_time + "logcat.log"
        cmd_logcat = "adb logcat -v time > %s" % logcat_log
        os.popen(cmd_logcat)
    else:
        print('请连接设备')
def get_tcp():
    '''测试流量,获取每一秒的流量'''
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' + GetPath.flow + '\\' + path +
             '.log')
    '''判断应用进程是否存在,获取应用pid'''
    try:
        content = os.popen("adb shell ps| findstr -e " +
                           Config().get_config()['pck_name']).read()
        pid = content.split()[1]
    except IndexError as e:
        print('测试应用的进程不存在,正在开启应用···')
        # 如果不需要自动启动,可以把下面这行命令注释掉
        os.popen('adb shell am start -W ' + Config().get_config()['pck_name'] +
                 '/' + Config().get_config()['activity'])
    '''数据写入Excel'''
    i = 0
    worksheet = workbook.add_sheet('MySheet')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, '上传流量')
    worksheet.write(0, 2, '下载流量')
    runtime = int(input("请输入测试时间(分钟):"))
    print('次数', '上行', '下载')
    rt = runtime * 60
    while i < rt:
        i = i + 1
        b = os.popen("adb shell cat /proc/" + pid + "/status")
        c = b.read()
        uid = re.search(r'(Uid).\s+(\d{0,5})', c).group(2)
        # 分别获得上行流量和下行流量
        snd = os.popen("adb shell cat /proc/uid_stat/" + uid +
                       "/tcp_snd").read().strip()
        snd_value = int(snd) // 1024
        rcv = os.popen("adb shell cat /proc/uid_stat/" + uid +
                       "/tcp_rcv").read().strip()
        rcv_value = int(rcv) // 1024
        time.sleep(1)
        print(i, snd_value, rcv_value)
        worksheet.write(i, 0, i, style)
        worksheet.write(i, 1, snd_value)
        worksheet.write(i, 2, rcv_value)
        # 数据保存地址,以Excel表格保存
        workbook.save(GetPath.flow + '\\' + path + '.xls')
    print('测试完毕。')
def get_tcp():
    '''测试流量'''
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' +
             Config().get_config()['flow_info'] + path + '.log')
    '''获取应用pid'''
    content = os.popen("adb shell ps| findstr -e " +
                       Config().get_config()['pck_name']).read()
    pid = content.split()[1]
    '''数据写入Excel'''
    i = 0
    worksheet = workbook.add_sheet('MySheet')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, '上传流量')
    worksheet.write(0, 2, '下载流量')
    '''获取每一秒的流量值'''
    rt = runtime * 60
    while i < rt:
        i = i + 1
        b = os.popen("adb shell cat /proc/" + pid + "/status")
        c = b.read()
        uid = re.search(r'(Uid).\s+(\d{0,5})', c).group(2)
        '''分别获得上行流量和下行流量,strip()函数去掉末尾的空行'''
        snd = os.popen("adb shell cat /proc/uid_stat/" + uid +
                       "/tcp_snd").read().strip()
        snd_value = int(snd) // 1024
        rcv = os.popen("adb shell cat /proc/uid_stat/" + uid +
                       "/tcp_rcv").read().strip()
        rcv_value = int(rcv) // 1024
        #print(i,snd,rcv)
        print(i, snd_value, rcv_value)
        worksheet.write(i, 0, i, style)
        worksheet.write(i, 1, snd_value)
        worksheet.write(i, 2, rcv_value)
        '''每秒获取一次数据'''
        time.sleep(1)
        workbook.save(Config().get_config()['flow_info'] + path + '.xlsx')
    print('测试完毕。')
def get_cpu_info():
    '''获取内存详情,每三秒读取一次内存值'''
    i = 0
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' +
             Config().get_config()['cpu_info'] + path + '.log')
    # 数据写入Excel
    worksheet = workbook.add_sheet('MySheet2')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, 'Total')
    worksheet.write(0, 2, 'user')
    worksheet.write(0, 3, 'kernel')
    worksheet.write(0, 4, 'iowait')
    worksheet.write(0, 5, 'irq')
    worksheet.write(0, 6, 'softirq')
    rt = runtime * 20
    while i < rt:
        i = i + 1
        worksheet.write(i, 0, i, style)
        process = (os.popen('adb shell dumpsys cpuinfo ' +
                            Config().get_config()['pck_name'])).readlines()
        output = process[-1]
        print(output)
        Total = output.split()[0]
        user = output.split()[2]
        kernel = output.split()[5]
        iowait = output.split()[8]
        irq = output.split()[11]
        softirq = output.split()[14]
        worksheet.write(i, 1, Total)
        worksheet.write(i, 2, user)
        worksheet.write(i, 3, kernel)
        worksheet.write(i, 4, iowait)
        worksheet.write(i, 5, irq)
        worksheet.write(i, 6, softirq)
        time.sleep(3)
        # 数据保存地址,以Excel表格保存
        workbook.save(Config().get_config()['cpu_info'] + path + '.xls')
Beispiel #14
0
 def update(self):
     if not Config.get('actions', 'DEBUG', cast=bool, default=False):
         os.system(
             f'cd {System.TOOL_PATH} && rm -rif {System.TOOL_NAME} && git clone https://github.com/Arab-developers/{System.TOOL_NAME}')
         tempPath = os.getcwd()
         run = f"python3 {os.path.abspath(os.path.join(HACKERMODE_PATH, 'base/bin/run.py'))}"
         TOOLS_PATH = os.path.abspath(os.path.join(HACKERMODE_PATH, 'base/tools'))
         try:
             for tool in os.listdir(TOOLS_PATH):
                 os.chdir(os.path.join(TOOLS_PATH, tool))
                 if os.path.isfile('setup.sh'):
                     os.system(f'{run} setup.sh')
         finally:
             os.chdir(tempPath)
     else:
         print("# can't update in the DEUBG mode!")
def get_mem_info():
    '''获取内存详情,每三秒读取一次内存值'''
    i = 0
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' + GetPath.mem_info + '\\' + path +
             '.log')
    # 数据写入Excel
    worksheet = workbook.add_sheet('MySheet4')
    worksheet.write(0, 0, '次数')
    worksheet.write(0, 1, 'Total')
    worksheet.write(0, 2, 'Java Heap')
    worksheet.write(0, 3, 'Native Heap')
    worksheet.write(0, 4, 'Stack')
    worksheet.write(0, 5, 'Graphics')
    worksheet.write(0, 6, 'Prinvate Other')
    worksheet.write(0, 7, 'System')
    worksheet.write(0, 8, 'TOTAL SWAP PSS')
    # 判断应用进程是否存在
    try:
        content = os.popen("adb shell ps| findstr -e " +
                           Config().get_config()['pck_name']).read()
        pid = content.split()[1]
    except IndexError as e:
        print('测试应用的进程不存在,正在开启应用···')
        # 如果不需要自动启动,可以把下面这行命令注释掉
        os.popen('adb shell am start -W ' + Config().get_config()['pck_name'] +
                 '/' + Config().get_config()['activity'])

    runtime = int(input("请输入测试时间(min):"))
    rt = runtime * 20
    while i < rt:
        i = i + 1
        worksheet.write(i, 0, i, style)
        out = os.popen("adb shell dumpsys meminfo " +
                       Config().get_config()['pck_name']).read()
        #print(out)
        # 读取内存数值
        JavaHeap = get_code(out, 'Java Heap:')
        NativeHeap = get_code(out, "Native Heap:")
        Stack = get_code(out, "Stack:")
        Graphics = get_code(out, "Graphics:")
        PrinvateOther = get_code(out, "Private Other:")
        System = get_code(out, "System:")
        Total = get_code(out, "TOTAL:")
        TotalSwapPss = get_code(out, "TOTAL SWAP PSS:")
        print('TOTAL:' + Total)
        print('Java Heap:' + JavaHeap)
        print("Native Heap:" + NativeHeap)
        print("Stack:" + Stack)
        print("Graphics:" + Graphics)
        print("Private Other:" + PrinvateOther)
        print("System:" + System)
        print("TOTAL SWAP PSS:" + TotalSwapPss)
        worksheet.write(i, 1, Total)
        worksheet.write(i, 2, JavaHeap)
        worksheet.write(i, 3, NativeHeap)
        worksheet.write(i, 4, Stack)
        worksheet.write(i, 5, Graphics)
        worksheet.write(i, 6, PrinvateOther)
        worksheet.write(i, 7, System)
        worksheet.write(i, 8, TotalSwapPss)
        time.sleep(3)

        # 数据保存地址,以Excel表格保存
        workbook.save(GetPath.mem_info + '\\' + path + '.xls')
Beispiel #16
0
#!/usr/bin/python3

import logging

from flask import Flask, request, jsonify

from base.ewallet_session_manager import EWalletSessionManager
from base.config import Config
from base.res_utils import ResUtils
from base.ewallet_dox import \
    display_ewallet_session_manager_instruction_set_option, \
    display_ewallet_session_manager_instruction_set_options

config, res_utils = Config(), ResUtils()
log = logging.getLogger(config.log_config['log_name'])
ewallet_session_manager = EWalletSessionManager(
    config=config, res_utils=res_utils,
)

app = Flask(__name__)

# HANDLERS


def handle_display_ewallet_session_manager_instruction_set_option(**kwargs):
    log.debug('')
    return display_ewallet_session_manager_instruction_set_option(**kwargs)


@app.route('/ewallet', methods=['GET'])
def handle_ewallet_session_manager_get_requests():
Beispiel #17
0
 def __init__(self, config=None):
     nn.Module.__init__(self)
     Config.__init__(self, config)
     self.proto = Protonet.Prototype()
Beispiel #18
0
 def get_app_uid(self):
     """根据app包名获取其uid号"""
     content = os.popen('adb shell pm dump ' + Config().get_config()['pck_name'] + ' | findstr "u0a"').read()
     uid = content.split()[-1].replace(':', '')
     print('%s的uid为:%s' % (Config().get_config()['pck_name'], uid))
     return uid
                c = b.read()
                d = re.search(r'(TOTAL)\s*(\d{0,8})', c)
                try:
                    mem = round(int(d.group(2)) / 1024, 2)
                except AttributeError:
                    mem = 0
                    pass
                print(proc + 'memValue:' + str(mem))
                j = j + 1
                name = str(pid) + proc
                if name not in processList:
                    processSum = processSum + 1
                    worksheet.write(0, processSum, name)
                    processList.append(name)
                processIndex = processList.index(name)
                if processIndex != -1:
                    worksheet.write(i, processIndex + 1, mem)
            workbook.save(Config().get_config()['mem_process'] + path +
                          '.xlsx')
        i = i + 1
        time.sleep(3)
    print('The test is finished!')


if __name__ == "__main__":
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime >' +
             Config().get_config()['mem_process'] + path + '.log')
    runtime = int(input("Please enter the test time(min):"))
    get_mem()
Beispiel #20
0
def get_cpu():
    cpu = os.popen("adb shell dumpsys cpuinfo " +
                   Config().get_config()['pck_name']).read()
Beispiel #21
0
def get_mem():
    mem = os.popen("adb shell dumpsys meminfo " +
                   Config().get_config()['pck_name']).read()
    Total = get_code(mem, "TOTAL:")
    print(Total)
Beispiel #22
0
def get_mem():
    '''查询多个进程的内存值'''
    j = 1
    i = 1
    # 判断应用进程是否存在
    try:
        content = os.popen("adb shell ps| findstr -e " +
                           Config().get_config()['pck_name']).read()
        pid = content.split()[1]
    except IndexError as e:
        print('测试应用的进程不存在,正在开启应用···')
        # 如果不需要自动启动,可以把下面这行命令注释掉
        os.popen('adb shell am start -W ' + Config().get_config()['pck_name'] +
                 '/' + Config().get_config()['activity'])
    # 抓取log
    os.popen('adb logcat -c')
    os.popen('adb logcat -v threadtime > ' + GetPath.mem_process + '\\' +
             path + '.log')
    processSum = 0
    processList = []
    worksheet = workbook.add_sheet('MySheet2')
    worksheet.write(0, 0, '次数')
    rt = runtime * 20
    while i < rt:
        '''每三秒获取一次内存值'''
        #print(contents)
        j = 0
        worksheet.write(i, 0, i, style)
        contents = os.popen("adb shell ps| findstr " +
                            Config().get_config()['pck_name']).readlines()
        while j < len(contents):
            if contents[j] == '\n':
                j = j + 1
            else:
                ''''遍历应用所有的进程和pid'''
                pid = contents[j].split()[1]
                #proc =contents[j].split()[8]
                try:
                    proc = re.search('(com.+)\n', contents[j]).group(1)
                except AttributeError:
                    continue
                '''Get all processes's memV'''
                b = os.popen('adb shell dumpsys meminfo ' + pid)
                c = b.read()
                d = re.search(r'(TOTAL)\s*(\d{0,8})', c)
                try:
                    mem = round(int(d.group(2)) / 1024, 2)
                except AttributeError:
                    mem = 0
                    pass
                print(proc + 'memValue:' + str(mem))
                j = j + 1
                name = str(pid) + proc
                if name not in processList:
                    processSum = processSum + 1
                    worksheet.write(0, processSum, name)
                    processList.append(name)
                processIndex = processList.index(name)
                if processIndex != -1:
                    worksheet.write(i, processIndex + 1, mem)
            workbook.save(GetPath.mem_process + '\\' + path + '.xlsx')
        i = i + 1
        time.sleep(3)
Beispiel #23
0
 def __init__(self, conf_fn='../dbsync.conf'):
     conf = Config(conf_fn).read_data()
     self.node = Node(conf)
Beispiel #24
0
 def get_uid(self):
     content = os.popen("adb shell ps| findstr " +
                        Config().get_config()['pck_name']).read()
     UID = content.split()[0].replace('_', '')
     return UID
Beispiel #25
0
 def __init__(self, config=None):
     nn.Module.__init__(self)
     Config.__init__(self, config)
     self._unfreeze(self.FINETUNE_LAYER_RANGE)
Beispiel #26
0
    def install(self):
        if not System.PLATFORME in ('termux', 'linux'):
            if System.PLATFORME == 'unknown':
                print("# The tool could not recognize the system!")
                print("# Do You want to continue anyway?")
                while True:
                    if input('# [Y/N]: ').lower() == 'y':
                        break
                    else:
                        print('# good bye :D')
                        return
            else:
                print(f"# The tool does not support {System.PLATFORME}")
                print('# good bye :D')
                return

        self.installer()

        # check:
        print('\n# checking:')
        self.check()

        if System.PLATFORME == "termux":
            try:
                os.listdir("/sdcard")
            except PermissionError:
                os.system("termux-setup-storage")

        if Config.get('actions', 'IS_INSTALLED', cast=bool, default=False):
            return

        # Move the tool to "System.TOOL_PATH"
        if not all(self.InstalledSuccessfully['base']):
            print(f'# {RED}Error:{NORMAL} some of the basics package not installed!')
            return

        if Config.get('actions', 'DEBUG', cast=bool, default=True):
            print('# In DEBUG mode can"t move the tool\n# to "System.TOOL_PATH"!')
            return

        if os.path.isdir(System.TOOL_NAME):
            HackerMode = '#!/usr/bin/python3\n'
            HackerMode += 'import sys,os\n'
            HackerMode += f'path=os.path.join("{System.TOOL_PATH}","{System.TOOL_NAME}")\n'
            HackerMode += "try:os.system(f'python3 -B {path} '+' '.join(sys.argv[1:]))\n"
            HackerMode += "except:pass"
            try:
                with open(os.path.join(System.BIN_PATH, System.TOOL_NAME), 'w') as f:
                    f.write(HackerMode)
                chmod = 'chmod' if System.PLATFORME == 'termux' else 'sudo chmod'
                os.system(f'{chmod} 777 {os.path.join(System.BIN_PATH, System.TOOL_NAME)}')
            except Exception as e:
                print(e)
                print('# installed failed!')
                return
            Config.set('actions', 'IS_INSTALLED', True)
            try:
                shutil.move(System.TOOL_NAME, System.TOOL_PATH)
                print(f'# {GREEN}HackerMode installed successfully...{NORMAL}')
            except shutil.Error as e:
                print(e)
                print('# installed failed!')
        else:
            print(f'{RED}# Error: the tool path not found!')
            print(f'# try to run tool using\n# {GREEN}"python3 HackerMode install"{NORMAL}')
            print('# installed failed!')
Beispiel #27
0
    def update_conf(self, option, value, section='node'):
        self.config.write_data(section, option, str(value))

    def add_peer(self, anode):
        self.ips.append(anode.ip)
        self.update_conf('cluster', 'ips', self.ips)

    def remove_peer(self, anode):
        ips = []
        for ip in self.ips:
            if ip != anode.ip:
                ips.append(ip)
        self.ips = ips
        self.update_conf('cluster', 'ips', self.ips)

    def join_cluster(self, cluster):
        pass

    def sync_data(self):
        pass

    def service(self):
        pass

if '__main__' == __name__:
    node = Node(Config('../dbsync.conf').read_data())
    print(node.cluster.node_ips)
    #    print(node.dbcs)
    print(node.database.exec('show tables;'))
Beispiel #28
0
 def __init__(self, nvim: neovim.Nvim) -> None:
     self.nvim = nvim
     self.config = Config.create(nvim.funcs.cwd())
Beispiel #29
0
 def reload(self, args):
     Config.create(self.nvim.funcs.cwd())
     return 'some string'
# 得到手机分辨率
def get_app_pix(dev):
    time.sleep(2)
    cmd = "adb -s " + dev + " shell wm size"
    #print(cmd)
    #return  subprocess.check_output(cmd).split()[2].decode()
    result = os.popen(cmd, "r")
    line = result.readline()
    while line:
        if str(line).find('Physical size') != -1:
            line = str(line).strip('\n')
            return str(line.split("Physical size:")[1])
        line = result.readline()


def get_phone_Kernel(dev):
    pix = get_app_pix(dev)
    men_total = get_men_total(dev)
    phone_msg = getModel(dev)
    cpu_sum = get_cpu_kel(dev)
    #print(dev + ":"+ pix,men_total,phone_msg,cpu_sum)
    return phone_msg, men_total, cpu_sum, pix


if __name__ == '__main__':
    # 读取配置文件中的设备名称
    dev = Config().get_config()['dev']
    m = getModel(dev)
    print(m)