|
24 | 24 | #include <stdio.h> |
25 | 25 | #include <stdlib.h> |
26 | 26 | #include <string.h> |
| 27 | +#include <unordered_map> |
| 28 | + |
| 29 | +#include <libterminal/terminal.hpp> |
27 | 30 |
|
28 | 31 | int countTasks() |
29 | 32 | { |
@@ -68,10 +71,13 @@ int procListCompareByParent(const void* a, const void* b) |
68 | 71 | return 1; |
69 | 72 | } |
70 | 73 |
|
| 74 | + |
| 75 | +std::unordered_map<g_tid, uint64_t> lastCpuTimes; |
| 76 | + |
71 | 77 | /** |
72 | 78 | * |
73 | 79 | */ |
74 | | -int procList(int argc, char** argv) |
| 80 | +int procList(int argc, char** argv, bool top) |
75 | 81 | { |
76 | 82 | bool threads = false; |
77 | 83 | for(int i = 0; i < argc; i++) |
@@ -105,14 +111,42 @@ int procList(int argc, char** argv) |
105 | 111 | qsort(taskData, taskCount, sizeof(g_kernquery_task_get_data), procListCompareByParent); |
106 | 112 |
|
107 | 113 | // print information |
108 | | - println("%5s %5s %6s %-20s %-38s", "pid", "tid", "mem", "id", "path"); |
| 114 | + if(top) |
| 115 | + { |
| 116 | + g_terminal::clear(); |
| 117 | + g_terminal::setCursor(g_term_cursor_position(0, 0)); |
| 118 | + } |
| 119 | + |
| 120 | + println("%4s %4s %-20s %-38s %5s %5s", "pid", "tid", "id", "path", "mem", top ? "cpu" : ""); |
109 | 121 | for(uint32_t pos = 0; pos < taskCount; pos++) |
110 | 122 | { |
111 | 123 | g_kernquery_task_get_data* entry = &taskData[pos]; |
112 | 124 |
|
113 | | - if(entry->id != -1 && (entry->type == G_TASK_TYPE_DEFAULT || entry->type == G_TASK_TYPE_VM86) && (threads || entry->id == entry->parent)) |
| 125 | + if(entry->id != -1 && (entry->type == G_TASK_TYPE_DEFAULT || entry->type == G_TASK_TYPE_VM86) && ( |
| 126 | + threads || entry->id == entry->parent)) |
114 | 127 | { |
115 | | - println("%5i %5i %6i %-20s %-38s", entry->parent, entry->id, entry->memory_used / 1024, entry->identifier, entry->source_path); |
| 128 | + if(top) |
| 129 | + { |
| 130 | + uint64_t cpuTimeTaken = entry->cpu_time - lastCpuTimes[entry->id]; |
| 131 | + lastCpuTimes[entry->id] = entry->cpu_time;; |
| 132 | + |
| 133 | + println("%4i %4i %-20s %-38s %5i %5i", |
| 134 | + entry->parent, |
| 135 | + entry->id, |
| 136 | + entry->identifier, |
| 137 | + entry->source_path, |
| 138 | + entry->memory_used / 1024, |
| 139 | + cpuTimeTaken / 1000000); |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + println("%4i %4i %-20s %-38s %5i", |
| 144 | + entry->parent, |
| 145 | + entry->id, |
| 146 | + entry->identifier, |
| 147 | + entry->source_path, |
| 148 | + entry->memory_used / 1024); |
| 149 | + } |
116 | 150 | } |
117 | 151 | } |
118 | 152 |
|
|
0 commit comments