mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-06 22:32:54 +02:00
fix time parser for missing centiseconds
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
jc changelog
|
||||
|
||||
20250330 v1.25.5
|
||||
20250331 v1.25.5
|
||||
- Add `amixer` command parser
|
||||
- Fix `time` command parser for output that does not contain centiseconds
|
||||
- Fix typing for upcoming python v3.14
|
||||
- Fix timezone setting for tests to support minimal chrooted builds
|
||||
|
||||
|
@ -132,7 +132,7 @@ import jc.utils
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
version = '1.5'
|
||||
description = '`/usr/bin/time` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -171,13 +171,18 @@ def _process(proc_data):
|
||||
proc_data['command_being_timed'] = proc_data['command_being_timed'][1:-1]
|
||||
|
||||
if 'elapsed_time' in proc_data:
|
||||
proc_data['elapsed_time'] = proc_data['elapsed_time'].replace('.', ':')
|
||||
*hours, minutes, seconds, centiseconds = proc_data['elapsed_time'].split(':')
|
||||
proc_data['elapsed_time'] = proc_data['elapsed_time'][::-1].replace(':', '.', 1)[::-1]
|
||||
*hours, minutes, ss = proc_data['elapsed_time'].split(':')
|
||||
if '.' in ss:
|
||||
seconds, centiseconds = ss.split('.')
|
||||
else:
|
||||
seconds = ss
|
||||
centiseconds = '0'
|
||||
|
||||
if hours:
|
||||
proc_data['elapsed_time_hours'] = jc.utils.convert_to_int(hours[0])
|
||||
else:
|
||||
proc_data['elapsed_time_hours'] = 0
|
||||
|
||||
proc_data['elapsed_time_minutes'] = jc.utils.convert_to_int(minutes)
|
||||
proc_data['elapsed_time_seconds'] = jc.utils.convert_to_int(seconds)
|
||||
proc_data['elapsed_time_centiseconds'] = jc.utils.convert_to_int(centiseconds)
|
||||
|
@ -113,6 +113,37 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.time.parse(self.osx_10_14_6_time_lp, quiet=True), self.osx_10_14_6_time_lp_json)
|
||||
|
||||
def test_time_no_centiseconds(self):
|
||||
"""
|
||||
Test 'time' output with no centiseconds data
|
||||
"""
|
||||
data = ''' Command being timed: "echo"
|
||||
User time (seconds): 5156.20
|
||||
System time (seconds): 0.05
|
||||
Percent of CPU this job got: 99%
|
||||
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:25:56
|
||||
Average shared text size (kbytes): 0
|
||||
Average unshared data size (kbytes): 0
|
||||
Average stack size (kbytes): 0
|
||||
Average total size (kbytes): 0
|
||||
Maximum resident set size (kbytes): 21760
|
||||
Average resident set size (kbytes): 0
|
||||
Major (requiring I/O) page faults: 0
|
||||
Minor (reclaiming a frame) page faults: 4975
|
||||
Voluntary context switches: 1
|
||||
Involuntary context switches: 8159
|
||||
Swaps: 0
|
||||
File system inputs: 0
|
||||
File system outputs: 6272
|
||||
Socket messages sent: 0
|
||||
Socket messages received: 0
|
||||
Signals delivered: 0
|
||||
Page size (bytes): 4096
|
||||
Exit status: 0'''
|
||||
|
||||
expected = {"command_being_timed":"echo","user_time":5156.2,"system_time":0.05,"cpu_percent":99,"elapsed_time":"1:25:56","average_shared_text_size":0,"average_unshared_data_size":0,"average_stack_size":0,"average_total_size":0,"maximum_resident_set_size":21760,"average_resident_set_size":0,"major_pagefaults":0,"minor_pagefaults":4975,"voluntary_context_switches":1,"involuntary_context_switches":8159,"swaps":0,"block_input_operations":0,"block_output_operations":6272,"messages_sent":0,"messages_received":0,"signals_delivered":0,"page_size":4096,"exit_status":0,"elapsed_time_hours":1,"elapsed_time_minutes":25,"elapsed_time_seconds":56,"elapsed_time_centiseconds":0,"elapsed_time_total_seconds":5156.0}
|
||||
self.assertEqual(jc.parsers.time.parse(data, quiet=True), expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user