Beispiel #1
0
    def run(self):
        user = androiddebug.shell(
            "su -c 'ls'").stdout.readline()  # 检查手机是否可以ROOT用户执行命令

        if "not found" in user:  # 非ROOT手机执行该方式
            serial_number = androiddebug.get_serialno()
            command = android_commands.AndroidCommands(serial_number)
            collector = surface_stats_collector.SurfaceStatsCollector(command)
            collector.DisableWarningAboutEmptyData()
            collector.Start()
            while True:
                if androiddebug.stop != True:
                    break
                tm = androiddebug.timestamp()
                results = collector.SampleResults()
                fpsdata = []
                if not results:
                    pass
                else:
                    for i in results:

                        if i.name == "avg_surface_fps":
                            if i.value == None:
                                fpsdata.insert(0, tm)
                                fpsdata.append(0)

                            else:
                                fpsdata.insert(0, tm)
                                fpsdata.append(i.value)
                self.ls.append(fpsdata)
            collector.Stop()

        else:  # ROOT手机执行该方式
            value1 = self.get_frame_data()
            self.time_before = value1["timestamp"]
            self.surface_before = value1["surface"]
            while True:
                if androiddebug.stop != True:
                    break
                y = []
                time.sleep(1)
                value2 = self.get_frame_data()
                self.time_after = value2["timestamp"]
                self.surface_after = value2["surface"]
                time_difference = int(
                    round((self.time_after - self.time_before), 2))
                frame_count = (self.surface_after - self.surface_before)
                tm = androiddebug.timestamp()
                fps = int(frame_count / time_difference)
                y.append(fps)
                self.time_before = self.time_after
                self.surface_before = self.surface_after
                y.insert(0, tm)
                self.ls.append(y)
def get_crash_log(time_list):
    log_file = PATH("%s/crash_log/%s.txt" %
                    (os.getcwd(), androiddebug.timestamp()))
    f = open(log_file, "w")
    for time in time_list:
        cash_log = androiddebug.shell("dumpsys dropbox --print %s" %
                                      time).stdout.read()
        f.write(cash_log)
    f.close()
Beispiel #3
0
def line_chart():
    data = top()
    cpu_data = []
    mem_data = []

    #去掉cpu占用率中的百分号,并转换为int型
    for cpu in data[0]:
        cpu_data.append(string.atoi(cpu.split("%")[0]))

    #去掉内存占用中的单位K,并转换为int型,以M为单位
    for mem in data[1]:
        mem_data.append(string.atof(mem.split("K")[0]) / 1024)

    #横坐标
    labels = []
    for i in range(1, times + 1):
        labels.append(str(i))

    #自动设置图表区域宽度
    if times <= 50:
        xArea = times * 40
    elif 50 < times <= 90:
        xArea = times * 20
    else:
        xArea = 1800

    c = XYChart(xArea, 800, 0xCCEEFF, 0x000000, 1)
    c.setPlotArea(60, 100, xArea - 100, 650)
    c.addLegend(50, 30, 0, "arialbd.ttf", 15).setBackground(Transparent)

    c.addTitle("cpu and memery info(%s)" % pkg_name, "timesbi.ttf",
               15).setBackground(0xCCEEFF, 0x000000, glassEffect())
    c.yAxis().setTitle("The numerical", "arialbd.ttf", 12)
    c.xAxis().setTitle("Times", "arialbd.ttf", 12)

    c.xAxis().setLabels(labels)

    #自动设置X轴步长
    if times <= 50:
        step = 1
    else:
        step = times / 50 + 1

    c.xAxis().setLabelStep(step)

    layer = c.addLineLayer()
    layer.setLineWidth(2)
    layer.addDataSet(cpu_data, 0xff0000, "cpu(%)")
    layer.addDataSet(mem_data, 0x008800, "mem(M)")

    path = PATH("%s/chart" % os.getcwd())
    if not os.path.isdir(path):
        os.makedirs(path)

    #图片保存至脚本当前目录的chart目录下
    c.makeChart(PATH("%s/%s.png" % (path, androiddebug.timestamp())))
def screenshot():
    path = PATH("%s/screenshot" % os.getcwd())
    androiddebug.shell("screencap -p /data/local/tmp/tmp.png").wait()
    if not os.path.isdir(path):
        os.makedirs(path)

    androiddebug.adb("pull /data/local/tmp/tmp.png %s" %
                     PATH("%s/%s.png" %
                          (path, androiddebug.timestamp()))).wait()
    androiddebug.shell("rm /data/local/tmp/tmp.png")
Beispiel #5
0
    def __init__(self):
        """
        初始化一个工作薄
        :return:
        """
        self.__workbook = xlsxwriter.Workbook(
            "{location}{time} {device}.xlsx".format(
                location="./chart/",
                time=androiddebug.timestamp(),
                device=androiddebug.get_device_name()),
            {'strings_to_numbers': True})

        self.format = self.__workbook.add_format(
            {'num_format': 'yyyy-mm-dd %H.%M.%S'})
        self.format_head = self.__workbook.add_format({'bold': True})
Beispiel #6
0
def record():
    androiddebug.shell("screenrecord /data/local/tmp/video.mp4")
    input_key = raw_input("Please press the Enter key to stop recording:\n")
    if input_key == "":
        androiddebug.adb("kill-server")

    print "Get Video file..."
    androiddebug.adb("start-server")
    time.sleep(1.5)

    path = PATH("%s/video" %os.getcwd())
    if not os.path.isdir(path):
        os.makedirs(path)

    androiddebug.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, androiddebug.timestamp()))).wait()
 def run(self):
     while True:
         if androiddebug.stop != True:
             break
         sleep(1)
         y = []
         tm = androiddebug.timestamp()
         result = androiddebug.shell(
             "cat /sys/class/thermal/thermal_zone0/temp").stdout.readline()
         if "No such file or directory" in result:
             result = 0
         y.append(tm)
         y.append("".join(list(result)[0:2]) + "." +
                  "".join(list(result)[2:]))
         self.ls.append(y)
 def run(self):
     while True:
         if androiddebug.stop != True:
             break
         sleep(1)
         y = []
         dictionaries = {}
         tm = androiddebug.timestamp()
         # 这个温度单位是:
         result = androiddebug.shell("dumpsys battery").stdout.readlines()
         for i in result[1:]:
             new = i.split(":")
             dictionaries[new[0].strip()] = new[1].strip()
         y.append(tm)
         y.append("".join(list(dictionaries["temperature"])[0:2]) + "." +
                  "".join(list(dictionaries["temperature"])[2:]))
         self.ls.append(y)
Beispiel #9
0
 def run(self):
     self.total_before = self.get_total_cpu_time()
     self.process_before = self.get_process_cpu_time()
     while True:
         if androiddebug.stop != True:
             break
         y = []
         sleep(1)
         tm = androiddebug.timestamp()
         self.total_after = self.get_total_cpu_time()
         self.process_after = self.get_process_cpu_time()
         usage = str(
             round(
                 float(self.process_after - self.process_before) /
                 float(self.total_after - self.total_before), 4) * 100)
         y.append(tm)
         y.append(usage)
         # print "CPU占用率:%s\n" % usage
         self.total_before = self.total_after
         self.process_before = self.process_after
         self.ls.append(y)