Skip to content

Commit

Permalink
Restore DiskSpaceMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Oct 5, 2023
1 parent 00aaf97 commit c6b4900
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/Processors/Editors/GenericEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ LevelMonitor::LevelMonitor(GenericProcessor *p) : Button("LevelMonitor")
processor = p;
updateFreq = 60; //10Hz
fillPercentage = 0.0;
lastUpdateTime = Time::getMillisecondCounterHiRes();
lastUpdateTime = 0.0;
stateChangeSinceLastUpdate = false;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Processors/RecordNode/RecordNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void RecordNode::parameterValueChanged(Parameter* p)

void RecordNode::checkDiskSpace()
{
int diskSpaceWarningThreshold = 5; //GB
float diskSpaceWarningThreshold = 5; //GB

File dataDir(dataDirectory);
int64 freeSpace = dataDir.getBytesFreeOnVolume();
Expand All @@ -165,7 +165,7 @@ void RecordNode::checkDiskSpace()

if (availableBytes < diskSpaceWarningThreshold && !isRecording)
{
String msg = "Less than " + String(diskSpaceWarningThreshold) + " GB of disk space available in " + String(dataDirectory.getFullPathName());
String msg = "Less than " + String(int(diskSpaceWarningThreshold)) + " GB of disk space available in " + String(dataDirectory.getFullPathName());
msg += ". Recording may fail. Please free up space or change the recording directory.";
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "WARNING", msg);
}
Expand Down
74 changes: 71 additions & 3 deletions Source/Processors/RecordNode/RecordNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,78 @@ DiskSpaceMonitor::DiskSpaceMonitor(RecordNode* rn)
recordingTimeLeftInSeconds(0),
dataRate(0.0)
{
startTimerHz(10);
startTimerHz(1);
}

DiskSpaceMonitor::~DiskSpaceMonitor() {}

void DiskSpaceMonitor::reset()
{
lastUpdateTime = Time::getMillisecondCounterHiRes();
lastFreeSpace = ((RecordNode*) processor)->getDataDirectory().getBytesFreeOnVolume();
}

void DiskSpaceMonitor::timerCallback()
{

RecordNode* recordNode = (RecordNode*) processor;

int64 bytesFree = recordNode->getDataDirectory().getBytesFreeOnVolume();
int64 volumeSize = recordNode->getDataDirectory().getVolumeTotalSize();

float ratio = float(bytesFree) / float(volumeSize);
if (ratio > 0)
setFillPercentage(1.0f - ratio);

float currentTime = Time::getMillisecondCounterHiRes();

if (recordNode->getRecordingStatus())
{
// Update data rate and recording time left every 30 seconds
if (currentTime - lastUpdateTime > 5000.0f)
{
dataRate = (lastFreeSpace - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms
lastUpdateTime = currentTime;
lastFreeSpace = bytesFree;

recordingTimeLeftInSeconds = bytesFree / dataRate / 1000.0f;

// Stop recording and show warning when less than 5 minutes of disk space left
if (dataRate > 0.0f && recordingTimeLeftInSeconds < (60.0f * 5.0f))
{
CoreServices::setRecordingStatus(false);
String msg = "Recording stopped. Less than 5 minutes of disk space remaining.";
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "WARNING", msg);
}

if (dataRate > 0.0f)
{
String msg = String(bytesFree / pow(2, 30)) + " GB available\n";
msg += String(int(recordingTimeLeftInSeconds / 60.0f)) + " minutes remaining\n";
msg += "Data rate: " + String(dataRate * 1000 / pow(2, 20), 2) + " MB/s";
setTooltip(msg);

LOGD("Data rate: ", dataRate, " bytes/ms");
}
}
}
else
{
setTooltip(String(bytesFree / pow(2, 30)) + " GB available");
}

/*
lastFreeSpace = recordNode->getDataDirectory().getBytesFreeOnVolume();
float bytesFree = (float) recordNode->getDataDirectory().getBytesFreeOnVolume();
float volumeSize = (float) recordNode->getDataDirectory().getVolumeTotalSize();
printf("Directory: %s\n", recordNode->getDataDirectory().getFullPathName().toRawUTF8());
printf("lastFreeSpace: %d\n", lastFreeSpace);
printf("Bytes free: %f\n", bytesFree);
printf("Volume size: %f\n", volumeSize);
float ratio = bytesFree / volumeSize;
if (ratio > 0)
Expand All @@ -77,15 +135,16 @@ void DiskSpaceMonitor::timerCallback()
float currentTime = Time::getMillisecondCounterHiRes();
// Update data rate and recording time left every 30 seconds
if (recordNode->getRecordingStatus() && currentTime - lastUpdateTime > 30000) {
if (recordNode->getRecordingStatus()) {
if (lastUpdateTime == 0.0) {
lastUpdateTime = Time::getMillisecondCounterHiRes();
lastFreeSpace = bytesFree;
}
else
{
dataRate = (lastFreeSpace - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms
dataRate = (float(lastFreeSpace) - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms
printf("dataRate = (%d - %f) / (%f - %f)\n", lastFreeSpace, bytesFree, currentTime, lastUpdateTime);
lastUpdateTime = currentTime;
lastFreeSpace = bytesFree;
Expand All @@ -105,8 +164,16 @@ void DiskSpaceMonitor::timerCallback()
msg += "Data rate: " + String(dataRate * 1000 / pow(2, 20), 2) + " MB/s";
setTooltip(msg);
}
LOGD("lastUpdateTime: ", lastUpdateTime);
LOGD("lastFreeSpace: ", lastFreeSpace);
LOGD("bytesFree: ", bytesFree);
LOGD("volumeSize: ", volumeSize);
LOGD("Free space: ", bytesFree / pow(2, 30), " GB");
}
*/

repaint();
}

Expand Down Expand Up @@ -456,6 +523,7 @@ void RecordNodeEditor::timerCallback()

void RecordNodeEditor::startRecording()
{
diskSpaceMonitor->reset();
/*
dataPathButton->setEnabled(false);
engineSelectCombo->setEnabled(false);
Expand Down
5 changes: 4 additions & 1 deletion Source/Processors/RecordNode/RecordNodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ class DiskSpaceMonitor : public LevelMonitor
/** Updates the display */
void timerCallback() override;

/** Resets timer */
void reset();

private:
int64 lastFreeSpace;
int64 recordingTimeLeftInSeconds;
float recordingTimeLeftInSeconds;
float dataRate;
};

Expand Down

0 comments on commit c6b4900

Please sign in to comment.