ProcFileSystem.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 NSCHED FDS NAME\n");
  24. for (auto* task : tasks) {
  25. ptr += ksprintf(ptr, "%w %w:%w %b %w %w %s\n",
  26. task->pid(),
  27. task->uid(),
  28. task->gid(),
  29. task->state(),
  30. task->timesScheduled(),
  31. task->fileHandleCount(),
  32. task->name().characters());
  33. }
  34. ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
  35. *ptr = '\0';
  36. return ByteBuffer::copy((byte*)buffer, ptr - buffer);
  37. }));
  38. return true;
  39. }
  40. const char* ProcFileSystem::className() const
  41. {
  42. return "procfs";
  43. }