Skip to content

Commit

Permalink
IbPerfMonitor/MonitorWindow: Use a mutex to prevent the performance c…
Browse files Browse the repository at this point in the history
…ounter from being changed while the window is refreshing
  • Loading branch information
fruhland committed Jul 24, 2018
1 parent 0532b07 commit cf701bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/IbPerfMon/IbPerfMon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ void IbPerfMon::Run() {
});
m_manager->AddMenuFunction("Reset All", [&] {
m_fabric->ResetCounters();
m_monitorWindow[0]->RefreshValues();
m_manager->RequestRefresh();
});
m_manager->AddMenuFunction("Single Window", [&] {
Expand Down
16 changes: 16 additions & 0 deletions src/IbPerfMon/MonitorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ MonitorWindow::~MonitorWindow() {
}

void MonitorWindow::DrawContent() {
m_refreshLock.lock();

ListWindow::DrawContent();

m_refreshLock.unlock();
}

void MonitorWindow::SetPerfCounter(IbPerfLib::IbPerfCounter *counter) {
m_refreshLock.lock();

m_perfCounter = counter;
m_highlight = 0;
m_xmitThroughput = 0;
m_rcvThroughput = 0;

RefreshValues();

m_refreshLock.unlock();
}

void MonitorWindow::RefreshValues() {
Expand Down Expand Up @@ -136,19 +144,27 @@ void MonitorWindow::RefreshValues() {
}

void MonitorWindow::ResetValues() {
m_refreshLock.lock();

m_perfCounter->ResetCounters();

m_xmitThroughput = 0;
m_rcvThroughput = 0;

RefreshValues();

m_refreshLock.unlock();
}

void MonitorWindow::RefreshThread() {
while (true) {
m_refreshLock.lock();

m_refreshThroughput = true;
RefreshValues();
CursesLib::WindowManager::GetInstance()->RequestRefresh();

m_refreshLock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(m_refreshInterval));
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/IbPerfMon/MonitorWindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef PROJECT_MONITORWINDOW_H
#define PROJECT_MONITORWINDOW_H

#include <thread>
#include <mutex>
#include <ncurses.h>
#include <IbPerfLib/IbPerfCounter.h>
#include <CursesLib/Window.h>
Expand Down Expand Up @@ -44,11 +46,6 @@ class MonitorWindow : public CursesLib::ListWindow {
*/
void SetPerfCounter(IbPerfLib::IbPerfCounter *counter);

/**
* Refresh the counters.
*/
void RefreshValues();

/**
* Reset the counters.
*/
Expand All @@ -60,6 +57,11 @@ class MonitorWindow : public CursesLib::ListWindow {
*/
void DrawContent() override;

/**
* Refresh the counters.
*/
void RefreshValues();

/**
* Refreshes the values in the given interval.
*/
Expand All @@ -83,6 +85,7 @@ class MonitorWindow : public CursesLib::ListWindow {
uint64_t m_xmitThroughput, m_rcvThroughput;
bool m_refreshThroughput;

std::mutex m_refreshLock;
std::thread m_refreshThread;
uint32_t m_refreshInterval;

Expand Down

0 comments on commit cf701bf

Please sign in to comment.