Skip to content

Commit fe3896c

Browse files
author
Diego Ferrari
committed
[MONITOR] gui and filter arguments
1 parent 14bb597 commit fe3896c

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

kernel/bin/monitor_processes.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ uint64_t calc_heap(uintptr_t ptr){
3737
return size;
3838
}
3939

40+
char *procname;
41+
4042
void print_process_info(){
4143
process_t *processes = get_all_processes();
4244
for (int i = 0; i < MAX_PROCS; i++){
4345
process_t *proc = &processes[i];
44-
if (proc->id != 0 && proc->state != STOPPED){
46+
if (proc->id != 0 && proc->state != STOPPED && (!procname || strcmp_case(procname,proc->name,true) == 0)){
4547
print("Process [%i]: %s [pid = %i | status = %s]",i,(uintptr_t)proc->name,proc->id,(uintptr_t)parse_proc_state(proc->state));
4648
print("Stack: %x (%x). SP: %x",proc->stack, proc->stack_size, proc->sp);
4749
print("Heap: %x (%x)",proc->heap, calc_heap(proc->heap_phys));
@@ -145,20 +147,38 @@ void draw_process_view(){
145147
commit_draw_ctx(&ctx);
146148
}
147149

148-
int monitor_procs(int argc, char* argv[]){
149-
bool visual = false;
150-
if (argc > 1){ //TODO: make this a proper parser once argv is fixed
151-
visual = true;
152-
request_draw_ctx(&ctx);
150+
bool visual;
151+
void show_help(char* name){
152+
print("Usage: %s [gui] <filter>",name);
153+
}
154+
155+
bool parse_args(int argc, char* argv[]){
156+
for (int i = 1; i < argc; i++){
157+
if (strcmp(argv[i],"gui") == 0){
158+
visual = true;
159+
request_draw_ctx(&ctx);
160+
}
161+
else if (strcmp(argv[i],"-help") == 0 || strcmp(argv[i],"-h") == 0){
162+
show_help(argv[0]);
163+
return false;
164+
}
165+
else if (strlen(argv[i])) procname = argv[i];
153166
}
167+
return true;
168+
}
169+
170+
int monitor_procs(int argc, char* argv[]){
171+
visual = false;
172+
if (!parse_args(argc, argv)) return 0;
154173
while (1){
155174
if (visual)
156175
draw_process_view();
157-
else
176+
else {
158177
print_process_info();
178+
msleep(5000);
179+
}
159180
kbd_event ev;
160181
if (read_event(&ev) && ev.key == KEY_ESC) return 0;
161-
msleep(5000);
162182
}
163183
return 1;
164184
}

0 commit comments

Comments
 (0)