|
13 | 13 | # ============================================================================== |
14 | 14 | parser = argparse.ArgumentParser( |
15 | 15 | description='Print elapsed time for every step in the flow') |
16 | | -parser.add_argument('--logDir', '-d', required=True, |
17 | | - help='Log files directory') |
| 16 | +parser.add_argument('--logDir', '-d', required=True, nargs='+', |
| 17 | + help='Log files directories') |
18 | 18 | parser.add_argument('--noHeader', action='store_true', |
19 | 19 | help='Skip the header') |
20 | 20 | args = parser.parse_args() |
|
25 | 25 | parser.print_help() |
26 | 26 | sys.exit(1) |
27 | 27 |
|
28 | | -first = True |
29 | | - |
30 | | -# Loop on all log files in the directory |
31 | | -for f in sorted(pathlib.Path(args.logDir).glob('**/[0-9]_*.log')): |
32 | | - # Extract Elapsed Time line from log file |
33 | | - with open(str(f)) as logfile: |
34 | | - found = False |
35 | | - for line in logfile: |
36 | | - elapsedTime = 0 |
37 | | - |
38 | | - if 'Elapsed time' in line: |
39 | | - found = True |
40 | | - # Extract the portion that has the time |
41 | | - timePor = line.strip().replace('Elapsed time: ', '') |
42 | | - # Remove the units from the time portion |
43 | | - timePor = timePor.split('[h:]', 1)[0] |
44 | | - # Remove any fraction of a second |
45 | | - timePor = timePor.split('.', 1)[0] |
46 | | - # Calculate elapsed time that has this format 'h:m:s' |
47 | | - timeList = timePor.split(':') |
48 | | - if len(timeList) == 2: |
49 | | - # Only minutes and seconds are present |
50 | | - elapsedTime = int(timeList[0])*60 + int(timeList[1]) |
51 | | - elif len(timeList) == 3: |
52 | | - # Hours, minutes, and seconds are present |
53 | | - elapsedTime = int(timeList[0])*3600 + int(timeList[1])*60 + int(timeList[2]) |
54 | | - else: |
55 | | - print('Elapsed time not understood in', str(line), file=sys.stderr) |
| 28 | +def print_log_dir_times(logdir): |
| 29 | + first = True |
| 30 | + print(logdir) |
56 | 31 |
|
57 | | - if not found: |
58 | | - print('No elapsed time found in', str(f), file=sys.stderr) |
59 | | - |
60 | | - # Print the name of the step and the corresponding elapsed time |
61 | | - if elapsedTime != 0: |
62 | | - if first and not args.noHeader: |
63 | | - print("%-25s %10s" % ("Log", "Elapsed seconds")) |
64 | | - first = False |
65 | | - print('%-25s %10s' % (os.path.splitext(os.path.basename(str(f)))[0], elapsedTime)) |
| 32 | + # Loop on all log files in the directory |
| 33 | + for f in sorted(pathlib.Path(logdir).glob('**/[0-9]_*.log')): |
| 34 | + # Extract Elapsed Time line from log file |
| 35 | + with open(str(f)) as logfile: |
| 36 | + found = False |
| 37 | + for line in logfile: |
| 38 | + elapsedTime = 0 |
| 39 | + |
| 40 | + if 'Elapsed time' in line: |
| 41 | + found = True |
| 42 | + # Extract the portion that has the time |
| 43 | + timePor = line.strip().replace('Elapsed time: ', '') |
| 44 | + # Remove the units from the time portion |
| 45 | + timePor = timePor.split('[h:]', 1)[0] |
| 46 | + # Remove any fraction of a second |
| 47 | + timePor = timePor.split('.', 1)[0] |
| 48 | + # Calculate elapsed time that has this format 'h:m:s' |
| 49 | + timeList = timePor.split(':') |
| 50 | + if len(timeList) == 2: |
| 51 | + # Only minutes and seconds are present |
| 52 | + elapsedTime = int(timeList[0])*60 + int(timeList[1]) |
| 53 | + elif len(timeList) == 3: |
| 54 | + # Hours, minutes, and seconds are present |
| 55 | + elapsedTime = int(timeList[0])*3600 + int(timeList[1])*60 + int(timeList[2]) |
| 56 | + else: |
| 57 | + print('Elapsed time not understood in', str(line), file=sys.stderr) |
| 58 | + |
| 59 | + if not found: |
| 60 | + print('No elapsed time found in', str(f), file=sys.stderr) |
| 61 | + |
| 62 | + # Print the name of the step and the corresponding elapsed time |
| 63 | + if elapsedTime != 0: |
| 64 | + if first and not args.noHeader: |
| 65 | + print("%-25s %10s" % ("Log", "Elapsed seconds")) |
| 66 | + first = False |
| 67 | + print('%-25s %10s' % (os.path.splitext(os.path.basename(str(f)))[0], elapsedTime)) |
| 68 | + |
| 69 | +for log_dir in args.logDir: |
| 70 | + print_log_dir_times(log_dir) |
0 commit comments