Add progress information.

This commit is contained in:
David Given
2022-09-03 13:24:51 +02:00
parent dbcd8c27c5
commit 6a1d181a34
6 changed files with 148 additions and 49 deletions

View File

@@ -83,8 +83,10 @@ std::string Logger::toString(const AnyLogMessage& message)
std::set<std::shared_ptr<const Record>> rawRecords;
for (const auto& trackDataFlux : track.trackDatas)
{
rawSectors.insert(trackDataFlux->sectors.begin(), trackDataFlux->sectors.end());
rawRecords.insert(trackDataFlux->records.begin(), trackDataFlux->records.end());
rawSectors.insert(trackDataFlux->sectors.begin(),
trackDataFlux->sectors.end());
rawRecords.insert(trackDataFlux->records.begin(),
trackDataFlux->records.end());
}
nanoseconds_t clock = 0;
@@ -136,6 +138,21 @@ std::string Logger::toString(const AnyLogMessage& message)
stream << fmt::format("{} bytes decoded\n", size);
},
/* Large-scale operation start. */
[&](const BeginOperationLogMessage& m)
{
},
/* Large-scale operation end. */
[&](const EndOperationLogMessage& m)
{
},
/* Large-scale operation progress. */
[&](const OperationProgressLogMessage& m)
{
},
/* Generic text message */
[&](const std::string& s)
{

View File

@@ -54,10 +54,24 @@ struct EndWriteOperationLogMessage
{
};
struct BeginOperationLogMessage
{
std::string message;
};
struct EndOperationLogMessage
{
std::string message;
};
struct OperationProgressLogMessage
{
unsigned progress;
};
class TrackFlux;
typedef std::variant<
std::string,
typedef std::variant<std::string,
ErrorLogMessage,
TrackReadLogMessage,
DiskReadLogMessage,
@@ -66,7 +80,10 @@ typedef std::variant<
BeginReadOperationLogMessage,
EndReadOperationLogMessage,
BeginWriteOperationLogMessage,
EndWriteOperationLogMessage>
EndWriteOperationLogMessage,
BeginOperationLogMessage,
EndOperationLogMessage,
OperationProgressLogMessage>
AnyLogMessage;
class Logger

View File

@@ -187,8 +187,17 @@ void writeTracks(FluxSink& fluxSink,
producer,
std::function<bool(const Location& location)> verifier)
{
for (const auto& location : Mapper::computeLocations())
Logger() << BeginOperationLogMessage{"Encoding and writing to disk"};
auto locations = Mapper::computeLocations();
int index = 0;
for (const auto& location : locations)
{
Logger() << OperationProgressLogMessage{
index * 100 / (unsigned)locations.size()};
index++;
testForEmergencyStop();
int retriesRemaining = config.decoder().retries();
@@ -237,6 +246,8 @@ void writeTracks(FluxSink& fluxSink,
retriesRemaining--;
}
}
Logger() << EndOperationLogMessage{"Write complete"};
}
static bool dontVerify(const Location&)
@@ -287,11 +298,17 @@ void writeTracksAndVerify(FluxSink& fluxSink,
Image wanted;
for (const auto& sector : encoder.collectSectors(location, image))
wanted.put(sector->logicalTrack, sector->logicalSide, sector->logicalSector)->data = sector->data;
wanted
.put(sector->logicalTrack,
sector->logicalSide,
sector->logicalSector)
->data = sector->data;
for (const auto& sector : trackFlux->sectors)
{
const auto s = wanted.get(sector->logicalTrack, sector->logicalSide, sector->logicalSector);
const auto s = wanted.get(sector->logicalTrack,
sector->logicalSide,
sector->logicalSector);
if (!s)
{
Logger() << "spurious sector on verify";
@@ -302,7 +319,9 @@ void writeTracksAndVerify(FluxSink& fluxSink,
Logger() << "data mismatch on verify";
return false;
}
wanted.erase(sector->logicalTrack, sector->logicalSide, sector->logicalSector);
wanted.erase(sector->logicalTrack,
sector->logicalSide,
sector->logicalSector);
}
if (!wanted.empty())
{
@@ -346,9 +365,8 @@ void writeRawDiskCommand(FluxSource& fluxSource, FluxSink& fluxSink)
dontVerify);
}
std::shared_ptr<TrackFlux> readAndDecodeTrack(FluxSource& fluxSource,
AbstractDecoder& decoder,
const Location& location)
std::shared_ptr<TrackFlux> readAndDecodeTrack(
FluxSource& fluxSource, AbstractDecoder& decoder, const Location& location)
{
auto trackFlux = std::make_shared<TrackFlux>();
trackFlux->location = location;
@@ -390,12 +408,18 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
auto diskflux = std::make_shared<DiskFlux>();
for (const auto& location : Mapper::computeLocations())
Logger() << BeginOperationLogMessage{"Reading and decoding disk"};
auto locations = Mapper::computeLocations();
unsigned index = 0;
for (const auto& location : locations)
{
Logger() << OperationProgressLogMessage{
index * 100 / (unsigned)locations.size()};
index++;
testForEmergencyStop();
auto trackFlux = readAndDecodeTrack(
fluxSource, decoder, location);
auto trackFlux = readAndDecodeTrack(fluxSource, decoder, location);
diskflux->tracks.push_back(trackFlux);
if (outputFluxSink)
@@ -478,6 +502,7 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
/* diskflux can't be modified below this point. */
Logger() << DiskReadLogMessage{diskflux};
Logger() << BeginOperationLogMessage{"Read complete"};
return diskflux;
}
@@ -494,10 +519,20 @@ void readDiskCommand(
void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)
{
for (unsigned track : iterate(config.tracks()))
Logger() << BeginOperationLogMessage{"Performing raw read of disk"};
auto tracks = iterate(config.tracks());
auto heads = iterate(config.heads());
unsigned locations = tracks.size() * heads.size();
unsigned index = 0;
for (unsigned track : tracks)
{
for (unsigned head : iterate(config.heads()))
for (unsigned head : heads)
{
Logger() << OperationProgressLogMessage{index * 100 / locations};
index++;
testForEmergencyStop();
auto fluxSourceIterator = fluxsource.readFlux(track, head);
@@ -511,6 +546,8 @@ void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)
fluxsink.writeFlux(track, head, *fluxmap);
}
}
Logger() << EndOperationLogMessage{"Raw read complete"};
}
void fillBitmapTo(std::vector<bool>& bitmap,

View File

@@ -92,6 +92,11 @@ void CustomStatusBar::SetProgress(int amount)
_progressBar->SetValue(amount);
}
void CustomStatusBar::SetLeftLabel(const std::string& text)
{
SetStatusText(text, 0);
}
void CustomStatusBar::SetRightLabel(const std::string& text)
{
_rightLabel->SetLabel(text);

View File

@@ -15,6 +15,7 @@ public:
void ShowProgressBar();
void HideProgressBar();
void SetProgress(int amount);
void SetLeftLabel(const std::string& text);
void SetRightLabel(const std::string& text);
private:

View File

@@ -481,6 +481,7 @@ public:
/* A fatal error. */
[&](const ErrorLogMessage& m)
{
_statusBar->SetLeftLabel(m.message);
wxMessageBox(m.message, "Error", wxOK | wxICON_ERROR);
_state = _errorState;
UpdateState();
@@ -523,6 +524,27 @@ public:
{
_currentDisk = m.disk;
},
/* Large-scale operation start. */
[&](const BeginOperationLogMessage& m)
{
_statusBar->SetLeftLabel(m.message);
_statusBar->ShowProgressBar();
},
/* Large-scale operation end. */
[&](const EndOperationLogMessage& m)
{
_statusBar->SetLeftLabel(m.message);
_statusBar->HideProgressBar();
},
/* Large-scale operation progress. */
[&](const OperationProgressLogMessage& m)
{
_statusBar->SetProgress(m.progress);
},
},
*message);
}