ProcessStacksWidget.cpp 979 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "ProcessStacksWidget.h"
  2. #include <LibCore/CFile.h>
  3. #include <LibCore/CTimer.h>
  4. #include <LibGUI/GBoxLayout.h>
  5. ProcessStacksWidget::ProcessStacksWidget(GWidget* parent)
  6. : GWidget(parent)
  7. {
  8. set_layout(make<GBoxLayout>(Orientation::Vertical));
  9. layout()->set_margins({ 4, 4, 4, 4 });
  10. m_stacks_editor = GTextEditor::construct(GTextEditor::Type::MultiLine, this);
  11. m_stacks_editor->set_readonly(true);
  12. m_timer = CTimer::construct(1000, [this] { refresh(); }, this);
  13. }
  14. ProcessStacksWidget::~ProcessStacksWidget()
  15. {
  16. }
  17. void ProcessStacksWidget::set_pid(pid_t pid)
  18. {
  19. if (m_pid == pid)
  20. return;
  21. m_pid = pid;
  22. refresh();
  23. }
  24. void ProcessStacksWidget::refresh()
  25. {
  26. CFile file(String::format("/proc/%d/stack", m_pid));
  27. if (!file.open(CIODevice::ReadOnly)) {
  28. m_stacks_editor->set_text(String::format("Unable to open %s", file.filename().characters()));
  29. return;
  30. }
  31. m_stacks_editor->set_text(file.read_all());
  32. }