ProcFileSystem.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. InterruptDisabler disabler;
  18. auto tasks = Task::allTasks();
  19. char* buffer;
  20. auto stringImpl = StringImpl::createUninitialized(tasks.size() * 256, buffer);
  21. memset(buffer, 0, stringImpl->length());
  22. char* ptr = buffer;
  23. ptr += ksprintf(ptr, "PID OWNER STATE PPID NSCHED FDS NAME\n");
  24. for (auto* task : tasks) {
  25. ptr += ksprintf(ptr, "%w %w:%w %b %w %x %w %s\n",
  26. task->pid(),
  27. task->uid(),
  28. task->gid(),
  29. task->state(),
  30. task->parentPID(),
  31. task->timesScheduled(),
  32. task->fileHandleCount(),
  33. task->name().characters());
  34. }
  35. ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
  36. *ptr = '\0';
  37. return ByteBuffer::copy((byte*)buffer, ptr - buffer);
  38. }));
  39. return true;
  40. }
  41. const char* ProcFileSystem::className() const
  42. {
  43. return "procfs";
  44. }