ert icon indicating copy to clipboard operation
ert copied to clipboard

Log peak memory usage to Azure

Open larsevj opened this issue 10 months ago • 0 comments

Currently the peak memory usage is logged outside of the PluginContext in log_process_usage, meaning that it is not included in the Azure logs. Would be useful to get statistics on the peak memory used in the FM's.

    try:
        with ErtPluginContext() as context:
            context.plugin_manager.add_logging_handle_to_root(logging.getLogger())
            logger.info(f"Running ert with {args}")
            args.func(args, context.plugin_manager)
    except (ErtCliError, ErtTimeoutError) as err:
        logger.exception(str(err))
        sys.exit(str(err))
    except ConfigValidationError as err:
        err_msg = err.cli_message()
        logger.exception(err_msg)
        sys.exit(err_msg)
    except BaseException as err:
        logger.exception(f'ERT crashed unexpectedly with "{err}"')

        logfiles = set()  # Use set to avoid duplicates...
        for loghandler in logging.getLogger().handlers:
            if isinstance(loghandler, logging.FileHandler):
                logfiles.add(loghandler.baseFilename)

        msg = f'ERT crashed unexpectedly with "{err}".\nSee logfile(s) for details:'
        msg += "\n   " + "\n   ".join(logfiles)

        sys.exit(msg)
    finally:
        log_process_usage()
        os.environ.pop("ERT_LOG_DIR")

larsevj avatar Apr 23 '24 14:04 larsevj