add logging module for debug output
This commit is contained in:
+27
-4
@@ -37,6 +37,7 @@ limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import csv
|
||||
import json
|
||||
import math
|
||||
@@ -58,7 +59,9 @@ from typing import Any, Iterable, Mapping, Union, List, Tuple, cast
|
||||
import msgpack
|
||||
import gzip
|
||||
|
||||
VERSION=0.3
|
||||
VERSION = 0.4
|
||||
|
||||
debug = 0
|
||||
|
||||
# Default GB per CPUs for the cluster
|
||||
default_mempercpu_gb = 2.2
|
||||
@@ -309,6 +312,16 @@ _ALLOWED_CMPOPS = {
|
||||
|
||||
##########################################
|
||||
|
||||
def _set_logging(debug: int):
|
||||
# always print warnings and errors
|
||||
level = logging.WARNING
|
||||
if debug >= 2:
|
||||
level = logging.DEBUG
|
||||
elif debug == 1:
|
||||
level = logging.INFO
|
||||
logging.basicConfig(level=level,
|
||||
format="(DBG %(levelname).1s) %(message)s")
|
||||
|
||||
####################################
|
||||
# Class for expression evaluations #
|
||||
####################################
|
||||
@@ -692,7 +705,8 @@ def run_sacct(args: argparse.Namespace) -> list[dict[str, str]]:
|
||||
if args.cluster:
|
||||
cmd += ["--cluster", args.cluster]
|
||||
|
||||
# print(f"DEBUG: sacct cmd: {cmd}")
|
||||
|
||||
logging.info(f"sacct cmd: {cmd}\n")
|
||||
|
||||
# Include job steps because MaxRSS often lives on batch/extern/step rows.
|
||||
# We later collapse rows back to the base job ID.
|
||||
@@ -1563,7 +1577,7 @@ def histo_graphs(out_rows: list[OutputRow], args: argparse.Namespace):
|
||||
f', "" using 1:{col+2} {linestyle} title "{names[col]}" \\\n'
|
||||
|
||||
gnuplot_cmd += "'\neval plot_cmd\n"
|
||||
#print(f"DEBUG: GNUPLOT_SCRIPT:\n{gnuplot_cmd}")
|
||||
logging.info(f"GNUPLOT_SCRIPT:\n{gnuplot_cmd}\n")
|
||||
try:
|
||||
run(["gnuplot"],
|
||||
input=gnuplot_cmd,
|
||||
@@ -1680,6 +1694,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||
p.add_argument("-O", "--output-raw", help="write a raw sacct output (ASCII) to this cache file (large).")
|
||||
p.add_argument("-F", "--from-raw", help="read raw sacct output cache from this ASCII file (that was produced by -O option).")
|
||||
p.add_argument("-i", "--info", help="show metadata information for the given binary cache file")
|
||||
p.add_argument("-d", "--debug",
|
||||
help="debug output. Flag can be used multiple times for increased output.",
|
||||
action="count", default=0)
|
||||
|
||||
|
||||
args = p.parse_args(argv)
|
||||
@@ -1691,7 +1708,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
|
||||
# die silently if pipe process dies before us
|
||||
# die silently if pipe process dies before us, e.g. when piping to "less"
|
||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
|
||||
args = parse_args(argv or sys.argv[1:])
|
||||
@@ -1700,6 +1717,12 @@ def main(argv: list[str] | None = None) -> int:
|
||||
show_cache_info(args.info)
|
||||
sys.exit(0)
|
||||
|
||||
global debug
|
||||
if args.debug:
|
||||
debug = args.debug
|
||||
_set_logging(debug)
|
||||
|
||||
|
||||
if args.write_binary_cache and os.path.exists(args.write_binary_cache):
|
||||
sys.stderr.write(f"WARNING, file exists: {args.write_binary_cache}. Balking out...\n")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user