Skip to content

Commit

Permalink
Add the option to output the longest running jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour authored and jain651 committed Apr 19, 2021
1 parent ef3b004 commit d68ad8c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/TestHarness/TestHarness.py
Expand Up @@ -570,6 +570,25 @@ def cleanup(self):
print((util.colorText( summary % (self.num_passed, self.num_skipped, self.num_pending, self.num_failed), "", html = True, \
colored=self.options.colored, code=self.options.code )))

if self.options.longest_jobs:
# Sort all jobs by run time
sorted_tups = sorted(self.test_table, key=lambda tup: float(tup[0].getTiming()), reverse=True)

print('\n%d longest running jobs:' % self.options.longest_jobs)
print(('-' * (util.TERM_COLS)))

# Copy the current options and force timing to be true so that
# we get times when we call formatResult() below
options_with_timing = copy.deepcopy(self.options)
options_with_timing.timing = True

for tup in sorted_tups[0:self.options.longest_jobs]:
job = tup[0]
if not job.isSkip() and float(job.getTiming()) > 0:
print(util.formatResult(job, options_with_timing, caveats=True))
if len(sorted_tups) == 0 or float(sorted_tups[0][0].getTiming()) == 0:
print('No jobs were completed.')

# Perform any write-to-disc operations
self.writeResults()

Expand Down Expand Up @@ -784,6 +803,7 @@ def parseCLArgs(self, argv):
parser.add_argument('--dbfile', nargs='?', action='store', dest='dbFile', help='Location to timings data base file. If not set, assumes $HOME/timingDB/timing.sqlite')
parser.add_argument('-l', '--load-average', action='store', type=float, dest='load', help='Do not run additional tests if the load average is at least LOAD')
parser.add_argument('-t', '--timing', action='store_true', dest='timing', help='Report Timing information for passing tests')
parser.add_argument('--longest-jobs', action='store', dest='longest_jobs', type=int, default=0, help='Print the longest running jobs upon completion')
parser.add_argument('-s', '--scale', action='store_true', dest='scaling', help='Scale problems that have SCALE_REFINE set')
parser.add_argument('-i', nargs=1, action='store', type=str, dest='input_file_name', default='', help='The test specification file to look for')
parser.add_argument('--libmesh_dir', nargs=1, action='store', type=str, dest='libmesh_dir', help='Currently only needed for bitten code coverage')
Expand Down
36 changes: 36 additions & 0 deletions python/TestHarness/tests/test_LongestJobs.py
@@ -0,0 +1,36 @@
#* This file is part of the MOOSE framework
#* https://www.mooseframework.org
#*
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html

import subprocess
from TestHarnessTestCase import TestHarnessTestCase

class TestHarnessTester(TestHarnessTestCase):
def testLongestJobs(self):
"""
Test for --longest-jobs in the TestHarness with 2 passing jobs, 1 failing job, and 1 skipped job.
"""
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.runTests('-i', 'longest_jobs', '--longest-jobs', '4')

output = cm.exception.output.decode('utf-8')

self.assertIn('4 longest running jobs', output)
self.assertRegex(output, r'longest running jobs(?s).*run_1')
self.assertRegex(output, r'longest running jobs(?s).*run_2')
self.assertRegex(output, r'longest running jobs(?s).*run_fail')
self.assertNotRegex(output, r'longest running jobs(?s).*run_skip')

def testLongestJobsNoneCompleted(self):
"""
Test for --longest-jobs in the TestHarness with no jobs ran.
"""
output = self.runTests('-i', 'longest_jobs', '--re', 'foo', '--longest-jobs', '100').decode('utf-8')

self.assertIn('100 longest running jobs', output)
self.assertNotRegex(output, r'longest running jobs(?s).*<No jobs were completed>')
6 changes: 6 additions & 0 deletions python/TestHarness/tests/tests
Expand Up @@ -9,6 +9,12 @@
requirement = "TestHarness shall report a non-failing status after a predetermined time of no activity"
issues = '#9280'
[../]
[./longest_jobs]
type = PythonUnitTest
input = test_LongestJobs.py
requirement = "TestHarness shall support the output of the longest running jobs"
issues = '#16752'
[../]
[./csvdiffs]
type = PythonUnitTest
input = test_CSVDiffs.py
Expand Down
19 changes: 19 additions & 0 deletions test/tests/test_harness/longest_jobs
@@ -0,0 +1,19 @@
[Tests]
[run_1]
type = RunApp
input = good.i
[]
[run_2]
type = RunApp
input = good.i
[]
[run_skip]
type = RunApp
skip = skip
input = good.i
[]
[run_fail]
type = RunCommand
command = "false"
[]
[]

0 comments on commit d68ad8c

Please sign in to comment.