1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-11 01:10:37 +02:00
Files
.github
completions
docs
parsers
acpi.md
airport.md
airport_s.md
apt_cache_show.md
apt_get_sqq.md
arp.md
asciitable.md
asciitable_m.md
blkid.md
bluetoothctl.md
cbt.md
cef.md
cef_s.md
certbot.md
chage.md
cksum.md
clf.md
clf_s.md
crontab.md
crontab_u.md
csv.md
csv_s.md
curl_head.md
date.md
datetime_iso.md
debconf_show.md
df.md
dig.md
dir.md
dmidecode.md
dpkg_l.md
du.md
efibootmgr.md
email_address.md
env.md
ethtool.md
file.md
find.md
findmnt.md
finger.md
free.md
fstab.md
git_log.md
git_log_s.md
git_ls_remote.md
gpg.md
group.md
gshadow.md
hash.md
hashsum.md
hciconfig.md
history.md
host.md
hosts.md
http_headers.md
id.md
ifconfig.md
ini.md
ini_dup.md
iostat.md
iostat_s.md
ip_address.md
ip_route.md
ipconfig.md
iptables.md
iw_scan.md
iwconfig.md
jar_manifest.md
jobs.md
jwt.md
kv.md
kv_dup.md
last.md
ls.md
ls_s.md
lsattr.md
lsb_release.md
lsblk.md
lsmod.md
lsof.md
lspci.md
lsusb.md
m3u.md
mdadm.md
mount.md
mpstat.md
mpstat_s.md
needrestart.md
netstat.md
nmcli.md
nsd_control.md
ntpq.md
openvpn.md
os_prober.md
os_release.md
passwd.md
path.md
path_list.md
pci_ids.md
pgpass.md
pidstat.md
pidstat_s.md
ping.md
ping_s.md
pip_list.md
pip_show.md
pkg_index_apk.md
pkg_index_deb.md
plist.md
postconf.md
proc.md
proc_buddyinfo.md
proc_cmdline.md
proc_consoles.md
proc_cpuinfo.md
proc_crypto.md
proc_devices.md
proc_diskstats.md
proc_driver_rtc.md
proc_filesystems.md
proc_interrupts.md
proc_iomem.md
proc_ioports.md
proc_loadavg.md
proc_locks.md
proc_meminfo.md
proc_modules.md
proc_mtrr.md
proc_net_arp.md
proc_net_dev.md
proc_net_dev_mcast.md
proc_net_if_inet6.md
proc_net_igmp.md
proc_net_igmp6.md
proc_net_ipv6_route.md
proc_net_netlink.md
proc_net_netstat.md
proc_net_packet.md
proc_net_protocols.md
proc_net_route.md
proc_net_tcp.md
proc_net_unix.md
proc_pagetypeinfo.md
proc_partitions.md
proc_pid_fdinfo.md
proc_pid_io.md
proc_pid_maps.md
proc_pid_mountinfo.md
proc_pid_numa_maps.md
proc_pid_smaps.md
proc_pid_stat.md
proc_pid_statm.md
proc_pid_status.md
proc_slabinfo.md
proc_softirqs.md
proc_stat.md
proc_swaps.md
proc_uptime.md
proc_version.md
proc_vmallocinfo.md
proc_vmstat.md
proc_zoneinfo.md
ps.md
resolve_conf.md
route.md
rpm_qi.md
rsync.md
rsync_s.md
semver.md
sfdisk.md
shadow.md
srt.md
ss.md
ssh_conf.md
sshd_conf.md
stat.md
stat_s.md
swapon.md
sysctl.md
syslog.md
syslog_bsd.md
syslog_bsd_s.md
syslog_s.md
systemctl.md
systemctl_lj.md
systemctl_ls.md
systemctl_luf.md
systeminfo.md
time.md
timedatectl.md
timestamp.md
toml.md
top.md
top_s.md
tracepath.md
traceroute.md
tune2fs.md
udevadm.md
ufw.md
ufw_appinfo.md
uname.md
universal.md
update_alt_gs.md
update_alt_q.md
upower.md
uptime.md
url.md
ver.md
veracrypt.md
vmstat.md
vmstat_s.md
w.md
wc.md
who.md
x509_cert.md
x509_csr.md
xml.md
xrandr.md
yaml.md
zipinfo.md
zpool_iostat.md
zpool_status.md
lib.md
readme.md
streaming.md
utils.md
jc
man
snap
templates
tests
.gitignore
CHANGELOG
CONTRIBUTING.md
EXAMPLES.md
LICENSE.md
MANIFEST.in
README-snap.md
README.md
_config.yml
build-completions.py
build-package.sh
doc2md.py
docgen.sh
install.sh
mangen.py
pypi-upload.sh
readmegen.py
requirements.txt
runtests-missing-libs.sh
runtests.sh
setup.cfg
setup.py
updatedocs.sh
jc/docs/parsers/time.md

161 lines
5.1 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.time"></a>
2021-03-31 20:19:46 -07:00
# jc.parsers.time
2022-01-25 17:07:47 -08:00
2022-03-04 13:27:39 -08:00
jc - JSON Convert `/usr/bin/time` command output parser
2021-03-31 20:19:46 -07:00
2022-05-28 12:41:36 -07:00
Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be
2022-01-19 17:30:14 -08:00
used to redirect the output to a file that can be read by `jc`.
2021-03-31 20:19:46 -07:00
2022-05-28 12:41:36 -07:00
Alternatively, the output from `/usr/bin/time` can be redirected to `STDOUT`
2022-01-19 17:30:14 -08:00
so `jc` can receive it.
2021-03-31 20:19:46 -07:00
2022-05-26 15:54:39 -07:00
> Note: `/usr/bin/time` is similar but different from the Bash builtin
> `time` command.
2021-03-31 20:19:46 -07:00
Usage (cli):
2022-01-25 18:03:34 -08:00
$ /usr/bin/time -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p
2021-03-31 20:19:46 -07:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
result = jc.parse('time', time_command_output)
2022-01-18 15:38:03 -08:00
2021-04-08 15:52:49 -07:00
Schema:
2022-05-26 15:54:39 -07:00
Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage,
https://man7.org/linux/man-pages/man1/time.1.html
2022-01-25 18:03:34 -08:00
{
"real_time": float,
"user_time": float,
"system_time": float,
"elapsed_time": string,
"elapsed_time_hours": integer,
"elapsed_time_minutes": integer,
"elapsed_time_seconds": integer,
"elapsed_time_centiseconds": integer,
"elapsed_time_total_seconds": float,
"cpu_percent": integer, # null if ?
"average_shared_text_size": integer,
"average_unshared_data_size": integer,
"average_unshared_stack_size": integer,
"average_shared_memory_size": integer,
"maximum_resident_set_size": integer,
"block_input_operations": integer, # [0]
"block_output_operations": integer, # [1]
"major_pagefaults": integer,
"minor_pagefaults": integer,
"swaps": integer,
"page_reclaims": integer,
"page_faults": integer,
"messages_sent": integer,
"messages_received": integer,
"signals_received": integer,
"voluntary_context_switches": integer,
"involuntary_context_switches": integer
"command_being_timed": string,
"average_stack_size": integer,
"average_total_size": integer,
"average_resident_set_size": integer,
"signals_delivered": integer,
"page_size": integer,
"exit_status": integer
}
[0] aka File system inputs
[1] aka File system outputs
Examples:
$ /usr/bin/time --verbose -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p
{
"command_being_timed": "sleep 2",
"user_time": 0.0,
"system_time": 0.0,
"cpu_percent": 0,
"elapsed_time": "0:02.00",
"average_shared_text_size": 0,
"average_unshared_data_size": 0,
"average_stack_size": 0,
"average_total_size": 0,
"maximum_resident_set_size": 2084,
"average_resident_set_size": 0,
"major_pagefaults": 0,
"minor_pagefaults": 72,
"voluntary_context_switches": 2,
"involuntary_context_switches": 1,
"swaps": 0,
"block_input_operations": 0,
"block_output_operations": 0,
"messages_sent": 0,
"messages_received": 0,
"signals_delivered": 0,
"page_size": 4096,
"exit_status": 0,
"elapsed_time_hours": 0,
"elapsed_time_minutes": 0,
"elapsed_time_seconds": 2,
"elapsed_time_centiseconds": 50,
"elapsed_time_total_seconds": 2.5
}
$ /usr/bin/time --verbose -o timefile.out sleep 2; cat timefile.out | \\
jc --time -p -r
{
"command_being_timed": "\"sleep 2\"",
"user_time": "0.00",
"system_time": "0.00",
"cpu_percent": "0",
"elapsed_time": "0:02.00",
"average_shared_text_size": "0",
"average_unshared_data_size": "0",
"average_stack_size": "0",
"average_total_size": "0",
"maximum_resident_set_size": "2084",
"average_resident_set_size": "0",
"major_pagefaults": "0",
"minor_pagefaults": "72",
"voluntary_context_switches": "2",
"involuntary_context_switches": "0",
"swaps": "0",
"block_input_operations": "0",
"block_output_operations": "0",
"messages_sent": "0",
"messages_received": "0",
"signals_delivered": "0",
"page_size": "4096",
"exit_status": "0"
}
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.time.parse"></a>
2022-03-05 12:15:14 -08:00
### parse
2022-01-25 17:07:47 -08:00
2021-03-31 20:19:46 -07:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2021-03-31 20:19:46 -07:00
```
Main text parsing function
2022-01-25 18:03:34 -08:00
Parameters:
2021-03-31 20:19:46 -07:00
2022-01-25 18:03:34 -08:00
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
2021-03-31 20:19:46 -07:00
2022-01-25 18:03:34 -08:00
Returns:
2021-03-31 20:19:46 -07:00
2022-01-25 18:03:34 -08:00
Dictionary. Raw or processed structured data.
2021-03-31 20:19:46 -07:00
2022-01-25 19:18:54 -08:00
### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd
2023-12-21 14:55:21 -08:00
Source: [`jc/parsers/time.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/time.py)
2022-07-16 20:52:19 -07:00
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)