Skip to content

Commit

Permalink
Fixing if the time command has comma in the output (#17207)
Browse files Browse the repository at this point in the history
Changes to fix gpcheckperf failure with an exception when sometime time command output
has a comma separator instead of a dot.
Steps to reproduce issue:

$export LC_ALL=de_DE_utf8
$time sleep 1
real	0m1,021s
user	0m0,001s
sys	0m0,005s

Fix: added check if comma present in the time output, replace it with a dot and continue parsing.

Testing: Added unit tests to check the output of parseMultiDDResult() in case of comma and dot.
  • Loading branch information
piyushc01 authored and August-beaulo committed May 17, 2024
1 parent 60319e9 commit cc1bf04
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions gpMgmt/bin/gpcheckperf
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def parseMultiDDResult(out):
if o.find('real') >= 0:
h = line[1:i]
o = o.split()
o[1] = o[1].replace(',', '.')
m = re.search("(^\d+.\d+)", o[1])
if m is None:
sys.exit('[Error] expected %s to be a floating point number' % o[1])
Expand Down
35 changes: 35 additions & 0 deletions gpMgmt/bin/gppylib/test/unit/test_unit_gpcheckperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,41 @@ def test_parseCommandLine_when_get_memory_succeeds(self, mock_get_memory):
self.subject.parseCommandLine()
self.assertEqual(self.subject.GV.opt['-S'], 246.0)

def test_parseMultiDDResult_when_output_regular(self):
inputText = """[localhost] dd if=/dev/zero of=/tmp/gpcheckperf_gpadmin/ddfile count=131072 bs=32768
[localhost] 131072+0 records in
[localhost] 131072+0 records out
[localhost] 4294967296 bytes transferred in 2.973025 secs (1444645536 bytes/sec)
[localhost]
[localhost] multidd total bytes 4294967296
[localhost] real 3.65
[localhost] user 0.18
[localhost] sys 2.52
"""
actual_result = self.subject.parseMultiDDResult(inputText)
(mbps, time, bytes) = actual_result["localhost"]
exp_mbps, exp_time, exp_bytes = (1122.1917808219177, 3.65, 4294967296)
self.assertEqual(mbps, exp_mbps)
self.assertEqual(time, exp_time)
self.assertEqual(bytes, exp_bytes)

def test_parseMultiDDResult_when_output_comma(self):
inputText = """[localhost] dd if=/dev/zero of=/tmp/gpcheckperf_gpadmin/ddfile count=131072 bs=32768
[localhost] 131072+0 records in
[localhost] 131072+0 records out
[localhost] 4294967296 bytes transferred in 2.973025 secs (1444645536 bytes/sec)
[localhost]
[localhost] multidd total bytes 4294967296
[localhost] real 3,65
[localhost] user 0,18
[localhost] sys 2,52
"""
actual_result = self.subject.parseMultiDDResult(inputText)
(mbps, time, bytes) = actual_result["localhost"]
exp_mbps, exp_time, exp_bytes = (1122.1917808219177, 3.65, 4294967296)
self.assertEqual(mbps, exp_mbps)
self.assertEqual(time, exp_time)
self.assertEqual(bytes, exp_bytes)

if __name__ == '__main__':
run_tests()

0 comments on commit cc1bf04

Please sign in to comment.