Skip to content

Commit

Permalink
IbPerfMon: Implement possibility to view up to four monitor windows a…
Browse files Browse the repository at this point in the history
…t once
  • Loading branch information
fruhland committed Jul 10, 2018
1 parent 059734e commit db55b6f
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 16 deletions.
120 changes: 105 additions & 15 deletions src/IbPerfMon/IbPerfMon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ IbPerfMon::IbPerfMon() :
m_manager(CursesLib::WindowManager::GetInstance()),
m_helpWindow(nullptr),
m_menuWindow(nullptr),
m_monitorWindow(nullptr),
m_isRunning(true)
{
snprintf(m_helpMessage, 512, "IbPerfMon %s - git %s\n"
Expand All @@ -40,15 +39,20 @@ IbPerfMon::IbPerfMon() :
"Licensed under GPL v3\n\n"
"Up/Down: Navigate menu\n"
"Right/Left: Open/Close menu entry\n"
"Enter: Select\n"
"Enter: Select for single view\n"
"1/2/3/4: Assign to window\n"
"Tab: Switch window", VERSION, GIT_REV, BUILD_DATE);
}

IbPerfMon::~IbPerfMon() {
delete m_helpWindow;
delete m_monitorWindow;
delete m_menuWindow;
delete m_fabric;

delete m_monitorWindow[0];
delete m_monitorWindow[1];
delete m_monitorWindow[2];
delete m_monitorWindow[3];
}

void IbPerfMon::Run() {
Expand All @@ -62,14 +66,17 @@ void IbPerfMon::Run() {

m_manager->AddMenuFunction("Help", [&] { m_manager->RegisterWindow(m_helpWindow); });
m_manager->AddMenuFunction("Reset Current", [&] {
m_monitorWindow->ResetValues();
m_monitorWindow[0]->ResetValues();
m_manager->RequestRefresh();
});
m_manager->AddMenuFunction("Reset All", [&] {
m_fabric->ResetCounters();
m_monitorWindow->RefreshValues();
m_monitorWindow[0]->RefreshValues();
m_manager->RequestRefresh();
});
m_manager->AddMenuFunction("Single Window", [&] { SetWindowCount(1); });
m_manager->AddMenuFunction("Dual Window", [&] { SetWindowCount(2); });
m_manager->AddMenuFunction("Quad Window", [&] { SetWindowCount(4); });
m_manager->AddMenuFunction("Exit", [&] { m_isRunning = false; });

StartMonitoring();
Expand Down Expand Up @@ -112,35 +119,118 @@ void IbPerfMon::StartMonitoring() {
uint32_t termHeight = m_manager->GetTerminalHeight();

m_menuWindow = new CursesLib::MenuWindow(0, 0, 70, termHeight - 1, "Menu");
m_monitorWindow = new MonitorWindow(70, 0, termWidth - 70, termHeight - 1,
m_fabric->GetNodes()[0]->GetDescription().c_str(), m_fabric->GetNodes()[0]);

m_monitorWindow[0] = new MonitorWindow(70, 0, termWidth - 70, termHeight - 1,
m_fabric->GetNodes()[0]->GetDescription().c_str(), m_fabric->GetNodes()[0]);
m_monitorWindow[1] = new MonitorWindow(70, 0, termWidth - 70, termHeight - 1,
m_fabric->GetNodes()[1]->GetDescription().c_str(), m_fabric->GetNodes()[1]);
m_monitorWindow[2] = new MonitorWindow(70, 0, termWidth - 70, termHeight - 1,
m_fabric->GetNodes()[2]->GetDescription().c_str(), m_fabric->GetNodes()[2]);
m_monitorWindow[3] = new MonitorWindow(70, 0, termWidth - 70, termHeight - 1,
m_fabric->GetNodes()[3]->GetDescription().c_str(), m_fabric->GetNodes()[3]);

m_menuWindow->AddKeyHandler('1', [&]() {
auto& item = m_menuWindow->GetSelectedItem();

m_monitorWindow[0]->SetPerfCounter(static_cast<IbPerfLib::IbPerfCounter*>(item.GetData()));
m_monitorWindow[0]->SetTitle(item.GetName());
});

m_menuWindow->AddKeyHandler('2', [&]() {
auto& item = m_menuWindow->GetSelectedItem();

m_monitorWindow[1]->SetPerfCounter(static_cast<IbPerfLib::IbPerfCounter*>(item.GetData()));
m_monitorWindow[1]->SetTitle(item.GetName());
});

m_menuWindow->AddKeyHandler('3', [&]() {
auto& item = m_menuWindow->GetSelectedItem();

m_monitorWindow[2]->SetPerfCounter(static_cast<IbPerfLib::IbPerfCounter*>(item.GetData()));
m_monitorWindow[2]->SetTitle(item.GetName());
});

m_menuWindow->AddKeyHandler('4', [&]() {
auto& item = m_menuWindow->GetSelectedItem();

m_monitorWindow[3]->SetPerfCounter(static_cast<IbPerfLib::IbPerfCounter*>(item.GetData()));
m_monitorWindow[3]->SetTitle(item.GetName());
});

for (IbPerfLib::IbNode *node : m_fabric->GetNodes()) {
CursesLib::MenuItem item(node->GetDescription().c_str(), [&, node]() {
m_monitorWindow->SetPerfCounter(node);
m_monitorWindow->SetTitle(node->GetDescription().c_str());
});
SetWindowCount(1);

m_monitorWindow[0]->SetPerfCounter(node);
m_monitorWindow[0]->SetTitle(node->GetDescription().c_str());
}, node);

for (IbPerfLib::IbPort *port : node->GetPorts()) {
char portName[10];

snprintf(portName, 10, "Port %d", unsigned(port->GetNum()));
item.AddSubitem(CursesLib::MenuItem(portName, [&, port, portName]() {
m_monitorWindow->SetPerfCounter(port);
m_monitorWindow->SetTitle(portName);
}));
SetWindowCount(1);

m_monitorWindow[0]->SetPerfCounter(port);
m_monitorWindow[0]->SetTitle(portName);
}, port));
}

m_menuWindow->AddItem(item);
}

m_manager->RegisterWindow(m_monitorWindow);
m_manager->RegisterWindow(m_monitorWindow[0]);
m_manager->RegisterWindow(m_menuWindow);

while (m_isRunning);

m_manager->DeregisterWindow(m_menuWindow);
m_manager->DeregisterWindow(m_monitorWindow);
m_manager->DeregisterWindow(m_monitorWindow[0]);
m_manager->DeregisterWindow(m_monitorWindow[1]);
m_manager->DeregisterWindow(m_monitorWindow[2]);
m_manager->DeregisterWindow(m_monitorWindow[3]);
}

void IbPerfMon::SetWindowCount(uint8_t windowCount) {
uint32_t termWidth = m_manager->GetTerminalWidth();
uint32_t termHeight = m_manager->GetTerminalHeight();

m_manager->DeregisterWindow(m_monitorWindow[0]);
m_manager->DeregisterWindow(m_monitorWindow[1]);
m_manager->DeregisterWindow(m_monitorWindow[2]);
m_manager->DeregisterWindow(m_monitorWindow[3]);

if(windowCount == 1) {
m_manager->RegisterWindow(m_monitorWindow[0]);

m_monitorWindow[0]->Move(70, 0);
m_monitorWindow[0]->Resize(termWidth - 70, (termHeight - 1));
} else if(windowCount == 2) {
m_manager->RegisterWindow(m_monitorWindow[1]);
m_manager->RegisterWindow(m_monitorWindow[0]);

m_monitorWindow[0]->Move(70, 0);
m_monitorWindow[0]->Resize(termWidth - 70, (termHeight - 1) / 2);
m_monitorWindow[1]->Move(70, (termHeight - 1) / 2);
m_monitorWindow[1]->Resize(termWidth - 70, (termHeight - 1) / 2);
} else if(windowCount == 4) {
m_manager->RegisterWindow(m_monitorWindow[3]);
m_manager->RegisterWindow(m_monitorWindow[2]);
m_manager->RegisterWindow(m_monitorWindow[1]);
m_manager->RegisterWindow(m_monitorWindow[0]);

m_monitorWindow[0]->Move(70, 0);
m_monitorWindow[0]->Resize(termWidth - 70, (termHeight - 1) / 4);
m_monitorWindow[1]->Move(70, (termHeight - 1) / 4);
m_monitorWindow[1]->Resize(termWidth - 70, (termHeight - 1) / 4);
m_monitorWindow[2]->Move(70, (termHeight - 1) / 2);
m_monitorWindow[2]->Resize(termWidth - 70, (termHeight - 1) / 4);
m_monitorWindow[3]->Move(70, (termHeight - 1) - (termHeight - 1) / 4);
m_monitorWindow[3]->Resize(termWidth - 70, (termHeight - 1) / 4);
}

CursesLib::WindowManager::GetInstance()->RequestRefresh();
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/IbPerfMon/IbPerfMon.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class IbPerfMon {
*/
void StartMonitoring();

void SetWindowCount(uint8_t windowCount);

private:

IbPerfLib::IbFabric *m_fabric;
Expand All @@ -72,7 +74,7 @@ class IbPerfMon {
char m_helpMessage[256];
CursesLib::OkMessageWindow *m_helpWindow;
CursesLib::MenuWindow *m_menuWindow;
MonitorWindow *m_monitorWindow;
MonitorWindow *m_monitorWindow[4];

bool m_isRunning;
};
Expand Down

0 comments on commit db55b6f

Please sign in to comment.