Show the amount of memory in GraphicsBitmaps in /bin/top.

This seems like an extremely relevant metric to track.
This commit is contained in:
Andreas Kling 2019-02-05 09:27:27 +01:00
parent b1e054ffe8
commit 41567c5bb9
6 changed files with 37 additions and 13 deletions

View file

@ -140,6 +140,9 @@ public:
void set_shared(bool shared) { m_shared = shared; }
bool is_bitmap() const { return m_is_bitmap; }
void set_is_bitmap(bool b) { m_is_bitmap = b; }
RetainPtr<Region> clone();
bool contains(LinearAddress laddr) const
{
@ -198,6 +201,7 @@ private:
bool m_readable { true };
bool m_writable { true };
bool m_shared { false };
bool m_is_bitmap { false };
Bitmap m_cow_map;
};

View file

@ -488,7 +488,7 @@ ByteBuffer procfs$all(InodeIdentifier)
auto processes = Process::all_processes();
StringBuilder builder;
auto build_process_line = [&builder] (Process* process) {
builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u\n",
builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u\n",
process->pid(),
process->times_scheduled(),
process->tty() ? process->tty()->pgid() : 0,
@ -503,7 +503,8 @@ ByteBuffer procfs$all(InodeIdentifier)
process->name().characters(),
process->amount_virtual(),
process->amount_resident(),
process->amount_shared()
process->amount_shared(),
process->amount_in_bitmaps()
);
};
build_process_line(Scheduler::colonel());

View file

@ -2201,6 +2201,16 @@ size_t Process::amount_virtual() const
return amount;
}
size_t Process::amount_in_bitmaps() const
{
size_t amount = 0;
for (auto& region : m_regions) {
if (region->is_bitmap())
amount += region->size();
}
return amount;
}
size_t Process::amount_resident() const
{
// FIXME: This will double count if multiple regions use the same physical page.

View file

@ -273,6 +273,7 @@ public:
size_t amount_virtual() const;
size_t amount_resident() const;
size_t amount_shared() const;
size_t amount_in_bitmaps() const;
Process* fork(RegisterDump&);
int exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);

View file

@ -23,10 +23,12 @@ GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size)
auto vmo = VMObject::create_anonymous(size_in_bytes);
m_client_region = process.allocate_region_with_vmo(LinearAddress(), size_in_bytes, vmo.copy_ref(), 0, "GraphicsBitmap (client)", true, true);
m_client_region->set_shared(true);
m_client_region->set_is_bitmap(true);
m_client_region->commit();
auto& server = WSMessageLoop::the().server_process();
m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (server)", true, false);
m_server_region->set_shared(true);
m_server_region->set_is_bitmap(true);
m_data = (RGBA32*)m_server_region->laddr().as_ptr();
}

View file

@ -15,8 +15,9 @@ struct Process {
String name;
String state;
String user;
unsigned virt;
unsigned res;
unsigned linear;
unsigned committed;
unsigned in_bitmaps;
unsigned nsched_since_prev;
unsigned cpu_percent;
unsigned cpu_percent_decimal;
@ -42,7 +43,7 @@ static Snapshot get_snapshot()
if (!ptr)
break;
auto parts = String(buf, Chomp).split(',');
if (parts.size() < 14)
if (parts.size() < 16)
break;
bool ok;
pid_t pid = parts[0].to_uint(ok);
@ -58,9 +59,11 @@ static Snapshot get_snapshot()
process.user = s_usernames->get(uid);
process.state = parts[7];
process.name = parts[11];
process.virt = parts[12].to_uint(ok);
process.linear = parts[12].to_uint(ok);
ASSERT(ok);
process.res = parts[13].to_uint(ok);
process.committed = parts[13].to_uint(ok);
ASSERT(ok);
process.in_bitmaps = parts[15].to_uint(ok);
ASSERT(ok);
snapshot.map.set(pid, move(process));
}
@ -79,17 +82,19 @@ int main(int, char**)
Vector<Process*> processes;
auto prev = get_snapshot();
usleep(10000);
for (;;) {
auto current = get_snapshot();
auto sum_diff = current.sum_nsched - prev.sum_nsched;
printf("\033[3J\033[H\033[2J");
printf("\033[47;30m%6s % 8s %8s %8s %8s %4s %s\033[K\033[0m\n",
printf("\033[47;30m%6s % 8s %8s %6s %6s %6s %4s %s\033[K\033[0m\n",
"PID",
"USER",
"STATE",
"VIRTUAL",
"RESIDENT",
"LINEAR",
"COMMIT",
"BITMAP",
"%CPU",
"NAME");
for (auto& it : current.map) {
@ -115,12 +120,13 @@ int main(int, char**)
});
for (auto* process : processes) {
printf("%6d % 8s %8s %8u %8u %2u.%1u %s\n",
printf("%6d % 8s %8s %6u %6u %6u %2u.%1u %s\n",
process->pid,
process->user.characters(),
process->state.characters(),
process->virt / 1024,
process->res / 1024,
process->linear / 1024,
process->committed / 1024,
process->in_bitmaps / 1024,
process->cpu_percent,
process->cpu_percent_decimal,
process->name.characters()