Пример #1
0
def _profiling_print_stats():
    global _profiling_stats
    if len(_profiling_stats) == 0:
        return

    total_used_time = _profiling_stats[-1]["timeline"]
    logger.debug(
        "-----------------total={}-----------top 10 step----------------------------"
        .format(format_time(total_used_time)))

    _profiling_stats = sorted(_profiling_stats,
                              key=lambda k: k['step_used'],
                              reverse=True)
    if len(_profiling_stats) > 10:
        _profiling_stats = _profiling_stats[:10]

    for stat in _profiling_stats:
        lineno = stat["lineno"]
        step_used = stat["step_used"]
        step_percent = step_used / total_used_time * 100

        logger.debug(
            "line {:4}: step_used={} percent={:.2f}% message={}".format(
                stat["lineno"], format_time(stat["step_used"]), step_percent,
                stat["message"]))
Пример #2
0
def load_settings(settings=None):
    if settings is None:
        settings = default_settings

    global g_setting
    g_setting = {}

    for setting in settings:
        with open(setting["path"], "r", encoding="utf-8") as setting_file:
            try:
                g_setting[setting["name"]] = yaml.load(setting_file,
                                                       Loader=yaml.FullLoader)
            except Exception as error:
                notify_error(
                    logger,
                    "配置表={}的格式有问题,具体问题请看下面的报错中的line $行数$ column $列数$来定位\n错误信息:{}\n"
                    .format(setting["name"], error))
                exit(0)

    ok, msg = check_settings(g_setting)
    if not ok:
        notify_error(logger, "配置表填写有误:\n{}".format(msg))
        exit(0)

    logger.info("setting loaded")
    logger.debug("setting={}".format(g_setting))
Пример #3
0
    def on_config_update(self, raw_config: dict):
        consoleHandler.setLevel(self.log_level_map[self.log_level])

        if multiprocessing.current_process().name == "MainProcess":
            logger.info("config loaded")
            logging.info("log level change to %s", self.log_level)
            logging.info("max thread is set to %d", self.multi_threading.max_thread)
            logger.debug("raw_config={}".format(raw_config))
            logger.debug("config={}".format(g_config))
Пример #4
0
def load_settings(settings=None):
    if settings is None:
        settings = default_settings

    global g_setting
    g_setting = {}

    for setting in settings:
        try:
            with open(setting["path"], "r", encoding="utf-8") as setting_file:
                g_setting[setting["name"]] = yaml.load(setting_file,
                                                       Loader=yaml.FullLoader)
        except FileNotFoundError as error:
            notify_error(
                logger, "没找到配置表={},你是否直接在压缩包中打开了?\n错误信息:{}\n".format(
                    setting["name"], error))
            sys.exit(0)
        except UnicodeDecodeError as error:
            notify_error(
                logger,
                "配置表={}的编码格式有问题,应为utf-8,如果使用系统自带记事本的话,请下载vscode或notepad++等文本编辑器\n错误信息:{}\n"
                .format(setting["name"], error))
            sys.exit(0)
        except Exception as error:
            notify_error(
                logger,
                "配置表={}的格式有问题,具体问题请看下面的报错中的line $行数$ column $列数$来定位\n错误信息:{}\n"
                .format(setting["name"], error))
            sys.exit(0)

    ok, msg = check_settings(g_setting)
    if not ok:
        notify_error(logger, "配置表填写有误:\n{}".format(msg))
        sys.exit(0)

    if multiprocessing.current_process().name == "MainProcess":
        logger.info("setting loaded")
        logger.debug("setting={}".format(g_setting))
Пример #5
0
def _profiling_print_debug_timing_info(message):
    global _profiling_last_step_time, _profiling_stats
    timeline = time.time() - _profiling_start_time
    used_time_since_last_step = time.time() - _profiling_last_step_time
    _profiling_last_step_time = time.time()

    # if message in ["初始化tkinter"]:
    #     return

    # if message not in ["读取各种装备与套装的图片"]:
    #     return

    stat = {
        "lineno": getframeinfo(stack()[1][0]).lineno,
        "timeline": timeline,
        "step_used": used_time_since_last_step,
        "message": message,
    }

    _profiling_stats.append(stat)

    logger.debug("line {:4}: timeline={} step_used={} message={}".format(
        stat["lineno"], format_time(stat["timeline"]),
        format_time(stat["step_used"]), stat["message"]))