sysutils/top: better ui

This commit is contained in:
2026-03-31 17:23:41 +03:00
parent 7064a21d8d
commit 677ec96c08
8 changed files with 232 additions and 47 deletions
+24 -1
View File
@@ -2,6 +2,7 @@ use core::{
fmt,
sync::atomic::{AtomicU32, AtomicUsize, Ordering},
task::{Context, Poll},
time::Duration,
};
use abi_lib::SyscallRegister;
@@ -31,17 +32,19 @@ use yggdrasil_abi::{
ExitCode, ProcessGroupId, ProcessId, Signal, ThreadEvent, ThreadSpawnOptions, WaitFlags,
options::ProcessOptionVariant,
},
time::SystemTime,
};
use crate::{
fs::sysfs::{
self,
attribute::{StringAttribute, StringAttributeOps},
attribute::{IntegerAttribute, IntegerAttributeOps, StringAttribute, StringAttributeOps},
object::KObject,
},
task::{
TaskContextImpl, ThreadId, futex::UserspaceMutex, thread::Thread, types::AllocateProcessId,
},
time,
vfs::{FileReadiness, FileSet, IoContext, NodeRef},
};
@@ -96,6 +99,7 @@ pub struct Process {
pub(crate) exit: OneTimeEvent<ExitCode>,
pub(crate) child_exit_notify: BoolEvent,
start_time: SystemTime,
sysfs_node: IrqSafeRwLock<Option<Arc<KObject<Weak<Process>>>>>,
/// Process I/O information
@@ -119,6 +123,7 @@ impl Process {
let name = info.name.into();
let id = ProcessId::new();
let start_time = time::monotonic_time();
let process = Arc::new(Self {
name: name.clone(),
id,
@@ -129,6 +134,7 @@ impl Process {
Some(info.space.clone()),
info.image,
)),
start_time,
signal_entry: AtomicUsize::new(0),
child_exit_notify: BoolEvent::new(),
exit: OneTimeEvent::new(),
@@ -187,6 +193,11 @@ impl Process {
// (process, thread)
// }
pub fn run_time(&self) -> Duration {
let now = time::monotonic_time();
now.checked_sub_time(&self.start_time).unwrap_or_default()
}
pub fn create_group() -> ProcessGroupId {
static ID: AtomicU32 = AtomicU32::new(1);
let id = ID.fetch_add(1, Ordering::AcqRel);
@@ -795,6 +806,7 @@ impl ProcessIo {
fn add_sysfs_node(process: &Arc<Process>) -> Arc<KObject<Weak<Process>>> {
struct Name;
struct Parent;
struct RunTime;
impl StringAttributeOps for Name {
type Data = Weak<Process>;
@@ -820,12 +832,23 @@ fn add_sysfs_node(process: &Arc<Process>) -> Arc<KObject<Weak<Process>>> {
}
}
impl IntegerAttributeOps<u64> for RunTime {
type Data = Weak<Process>;
const NAME: &'static str = "runtime";
fn read(state: &Self::Data) -> Result<u64, Error> {
let process = state.upgrade().ok_or(Error::ProcessNotFound)?;
Ok(process.run_time().as_secs())
}
}
let name = format!("{}", process.id);
let process = Arc::downgrade(process);
let object = KObject::new(process);
object.add_attribute(StringAttribute::from(Name)).ok();
object.add_attribute(StringAttribute::from(Parent)).ok();
object.add_attribute(IntegerAttribute::from(RunTime)).ok();
if let Some(proc) = sysfs::proc() {
proc.add_object(name, object.clone()).ok();
+16 -1
View File
@@ -124,8 +124,23 @@ bitflags! {
fn dump_user_exception(kind: ExceptionKind, frame: &ExceptionFrame) {
let thread = Thread::current();
let image_base = if let Some(process) = thread.try_get_process() {
process.image_base()
} else {
None
};
log::warn!("{:?} in {} ({:?})", kind, thread.id, *thread.name.read());
log::warn!("ip = {:02x}:{:08x}", frame.cs, frame.rip);
if let Some(image_base) = image_base {
let rip_relative = frame.rip.saturating_sub(image_base as u64);
log::warn!(
"ip = {:#04x}:{:#010x} ({:#010x})",
frame.cs,
frame.rip,
rip_relative
);
} else {
log::warn!("ip = {:#04x}:{:#010x}", frame.cs, frame.rip);
}
log::warn!("cr3 = {:#010x}", CR3.get());
if kind == ExceptionKind::PageFault {
log::warn!("cr2 = {:#010x}", CR2.get());