...
This commit is contained in:
32
examples/osal/tmux_process_info.vsh
Normal file
32
examples/osal/tmux_process_info.vsh
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
|
import freeflowuniverse.herolib.osal.tmux
|
||||||
|
import freeflowuniverse.herolib.osal.core as osal
|
||||||
|
import time
|
||||||
|
|
||||||
|
mut t := tmux.new()!
|
||||||
|
if !t.is_running()! {
|
||||||
|
t.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a session and window
|
||||||
|
mut session := t.session_create(name: 'test')!
|
||||||
|
mut window := session.window_new(name: 'monitoring', cmd: 'top', reset: true)!
|
||||||
|
|
||||||
|
// Wait a moment for the process to start
|
||||||
|
time.sleep(1000 * time.millisecond)
|
||||||
|
|
||||||
|
// Get the active pane
|
||||||
|
if mut pane := window.pane_active() {
|
||||||
|
// Get process info for the pane and its children
|
||||||
|
process_map := pane.processinfo()!
|
||||||
|
|
||||||
|
println('Process tree for pane ${pane.id}:')
|
||||||
|
for process in process_map.processes {
|
||||||
|
println(' PID: ${process.pid}, CPU: ${process.cpu_perc}%, Memory: ${process.mem_perc}%, Command: ${process.cmd}')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get just the main process info
|
||||||
|
main_process := pane.processinfo_main()!
|
||||||
|
println('\nMain process: PID ${main_process.pid}, Command: ${main_process.cmd}')
|
||||||
|
}
|
||||||
@@ -129,3 +129,21 @@ pub fn (mut p Pane) output_wait(c_ string, timeoutsec int) ! {
|
|||||||
time.sleep(100 * time.millisecond)
|
time.sleep(100 * time.millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get process information for this pane and all its children
|
||||||
|
pub fn (mut p Pane) processinfo() !osal.ProcessMap {
|
||||||
|
if p.pid == 0 {
|
||||||
|
return error('Pane has no associated process (pid is 0)')
|
||||||
|
}
|
||||||
|
|
||||||
|
return osal.processinfo_with_children(p.pid)!
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get process information for just this pane's main process
|
||||||
|
pub fn (mut p Pane) processinfo_main() !osal.ProcessInfo {
|
||||||
|
if p.pid == 0 {
|
||||||
|
return error('Pane has no associated process (pid is 0)')
|
||||||
|
}
|
||||||
|
|
||||||
|
return osal.processinfo_get(p.pid)!
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user