ProcFileSystem.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "ProcFileSystem.h"
  2. #include "Task.h"
  3. RetainPtr<ProcFileSystem> ProcFileSystem::create()
  4. {
  5. return adopt(*new ProcFileSystem);
  6. }
  7. ProcFileSystem::ProcFileSystem()
  8. {
  9. }
  10. ProcFileSystem::~ProcFileSystem()
  11. {
  12. }
  13. bool ProcFileSystem::initialize()
  14. {
  15. SyntheticFileSystem::initialize();
  16. addFile(createGeneratedFile("summary", [] {
  17. cli();
  18. auto tasks = Task::allTasks();
  19. char* buffer;
  20. auto stringImpl = StringImpl::createUninitialized(tasks.size() * 128, buffer);
  21. memset(buffer, 0, stringImpl->length());
  22. char* ptr = buffer;
  23. ptr += ksprintf(ptr, "PID OWNER STATE NAME\n");
  24. for (auto* task : tasks) {
  25. ptr += ksprintf(ptr, "%w %w:%w %b %s\n",
  26. task->pid(),
  27. task->uid(),
  28. task->gid(),
  29. task->state(),
  30. task->name().characters());
  31. }
  32. ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
  33. *ptr = '\0';
  34. sti();
  35. return ByteBuffer::copy((byte*)buffer, ptr - buffer);
  36. }));
  37. return true;
  38. }
  39. const char* ProcFileSystem::className() const
  40. {
  41. return "procfs";
  42. }