summaryrefslogtreecommitdiff
path: root/Kernel/ProcFileSystem.cpp
blob: 039d8c897d44b57ffaa18e9fda7464e344ac5f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "ProcFileSystem.h"
#include "Task.h"

RetainPtr<ProcFileSystem> ProcFileSystem::create()
{
    return adopt(*new ProcFileSystem);
}

ProcFileSystem::ProcFileSystem()
{
}

ProcFileSystem::~ProcFileSystem()
{
}

bool ProcFileSystem::initialize()
{
    SyntheticFileSystem::initialize();
    addFile(createGeneratedFile("summary", [] {
        InterruptDisabler disabler;
        auto tasks = Task::allTasks();
        char* buffer;
        auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
        memset(buffer, 0, stringImpl->length());
        char* ptr = buffer;
        ptr += ksprintf(ptr, "PID    OWNER      STATE  NSCHED  FDS    NAME\n");
        for (auto* task : tasks) {
            ptr += ksprintf(ptr, "%w   %w:%w  %b     %w    %w   %s\n",
                task->pid(),
                task->uid(),
                task->gid(),
                task->state(),
                task->timesScheduled(),
                task->fileHandleCount(),
                task->name().characters());
        }
        ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
        *ptr = '\0';
        return ByteBuffer::copy((byte*)buffer, ptr - buffer);
    }));
    return true;
}

const char* ProcFileSystem::className() const
{
    return "procfs";
}