Skip to content

Commit

Permalink
add kernel_sys.py to contrib
Browse files Browse the repository at this point in the history
This script mimics crash>sys and provides the following output:

CPUS             16
DATE             Fri Jan 27 20:26:24 2023
UPTIME           1 day, 7:29:37
LOAD AVERAGE     0.00, 0.00, 0.00
TASKS            317
NODENAME         tw
RELEASE          6.1.7-1-default
VERSION          osandov#1 SMP PREEMPT_DYNAMIC Wed Jan 18 11:12:34 UTC 2023 (872045c)
MACHINE          x86_64
MEMORY           12.67 GiB

Signed-off-by: Martin Liska <[email protected]>
  • Loading branch information
marxin committed Feb 8, 2023
1 parent 93cd8ee commit c238392
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions contrib/kernel_sys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env drgn
# Copyright (c) SUSE Linux.
# SPDX-License-Identifier: LGPL-2.1-or-later

"""Display system information and configuration data."""

from datetime import datetime
from datetime import timedelta

from drgn.helpers.common.format import number_in_binary_units
from drgn.helpers.linux import for_each_online_cpu
from drgn.helpers.linux.mm import totalram_pages
from drgn.helpers.linux.pid import for_each_task
from drgn.helpers.linux.sched import loadavg


def print_line(key, value):
print(f"{key:<16} {value}")


uts = prog["init_uts_ns"].name

timekeeper = prog["shadow_timekeeper"]
date = datetime.fromtimestamp(timekeeper.xtime_sec).strftime("%c")
uptime = timedelta(seconds=timekeeper.ktime_sec.value_())
load = ", ".join([f"{v:.2f}" for v in loadavg(prog)])
totalram = (prog['PAGE_SIZE'] * totalram_pages(prog)).value_()


print_line("CPUS", len(list(for_each_online_cpu(prog))))
print_line("DATE", date)
print_line("UPTIME", uptime)
print_line("LOAD AVERAGE", load)
print_line("TASKS", len(list(for_each_task(prog))))
print_line("NODENAME", uts.nodename.string_().decode())
print_line("RELEASE", uts.release.string_().decode())
print_line("VERSION", uts.version.string_().decode())
print_line("MACHINE", uts.machine.string_().decode())
print_line("MEMORY", number_in_binary_units(totalram))

0 comments on commit c238392

Please sign in to comment.