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; std::set<std::shared_ptr<const Record>> rawRecords;
for (const auto& trackDataFlux : track.trackDatas) for (const auto& trackDataFlux : track.trackDatas)
{ {
rawSectors.insert(trackDataFlux->sectors.begin(), trackDataFlux->sectors.end()); rawSectors.insert(trackDataFlux->sectors.begin(),
rawRecords.insert(trackDataFlux->records.begin(), trackDataFlux->records.end()); trackDataFlux->sectors.end());
rawRecords.insert(trackDataFlux->records.begin(),
trackDataFlux->records.end());
} }
nanoseconds_t clock = 0; nanoseconds_t clock = 0;
@@ -136,6 +138,21 @@ std::string Logger::toString(const AnyLogMessage& message)
stream << fmt::format("{} bytes decoded\n", size); 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 */ /* Generic text message */
[&](const std::string& s) [&](const std::string& s)
{ {

View File

@@ -10,7 +10,7 @@ class Sector;
struct ErrorLogMessage struct ErrorLogMessage
{ {
std::string message; std::string message;
}; };
struct BeginSpeedOperationLogMessage struct BeginSpeedOperationLogMessage
@@ -29,7 +29,7 @@ struct TrackReadLogMessage
struct DiskReadLogMessage struct DiskReadLogMessage
{ {
std::shared_ptr<const DiskFlux> disk; std::shared_ptr<const DiskFlux> disk;
}; };
struct BeginReadOperationLogMessage struct BeginReadOperationLogMessage
@@ -40,8 +40,8 @@ struct BeginReadOperationLogMessage
struct EndReadOperationLogMessage struct EndReadOperationLogMessage
{ {
std::shared_ptr<const TrackDataFlux> trackDataFlux; std::shared_ptr<const TrackDataFlux> trackDataFlux;
std::set<std::shared_ptr<const Sector>> sectors; std::set<std::shared_ptr<const Sector>> sectors;
}; };
struct BeginWriteOperationLogMessage struct BeginWriteOperationLogMessage
@@ -54,19 +54,36 @@ struct EndWriteOperationLogMessage
{ {
}; };
struct BeginOperationLogMessage
{
std::string message;
};
struct EndOperationLogMessage
{
std::string message;
};
struct OperationProgressLogMessage
{
unsigned progress;
};
class TrackFlux; class TrackFlux;
typedef std::variant< typedef std::variant<std::string,
std::string, ErrorLogMessage,
ErrorLogMessage,
TrackReadLogMessage, TrackReadLogMessage,
DiskReadLogMessage, DiskReadLogMessage,
BeginSpeedOperationLogMessage, BeginSpeedOperationLogMessage,
EndSpeedOperationLogMessage, EndSpeedOperationLogMessage,
BeginReadOperationLogMessage, BeginReadOperationLogMessage,
EndReadOperationLogMessage, EndReadOperationLogMessage,
BeginWriteOperationLogMessage, BeginWriteOperationLogMessage,
EndWriteOperationLogMessage> EndWriteOperationLogMessage,
BeginOperationLogMessage,
EndOperationLogMessage,
OperationProgressLogMessage>
AnyLogMessage; AnyLogMessage;
class Logger class Logger

View File

@@ -187,8 +187,17 @@ void writeTracks(FluxSink& fluxSink,
producer, producer,
std::function<bool(const Location& location)> verifier) 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(); testForEmergencyStop();
int retriesRemaining = config.decoder().retries(); int retriesRemaining = config.decoder().retries();
@@ -237,6 +246,8 @@ void writeTracks(FluxSink& fluxSink,
retriesRemaining--; retriesRemaining--;
} }
} }
Logger() << EndOperationLogMessage{"Write complete"};
} }
static bool dontVerify(const Location&) static bool dontVerify(const Location&)
@@ -285,30 +296,38 @@ void writeTracksAndVerify(FluxSink& fluxSink,
return false; return false;
} }
Image wanted; Image wanted;
for (const auto& sector : encoder.collectSectors(location, image)) 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) for (const auto& sector : trackFlux->sectors)
{ {
const auto s = wanted.get(sector->logicalTrack, sector->logicalSide, sector->logicalSector); const auto s = wanted.get(sector->logicalTrack,
if (!s) sector->logicalSide,
{ sector->logicalSector);
Logger() << "spurious sector on verify"; if (!s)
return false; {
} Logger() << "spurious sector on verify";
if (s->data != sector->data.slice(0, s->data.size())) return false;
{ }
Logger() << "data mismatch on verify"; if (s->data != sector->data.slice(0, s->data.size()))
return false; {
} Logger() << "data mismatch on verify";
wanted.erase(sector->logicalTrack, sector->logicalSide, sector->logicalSector); return false;
} }
if (!wanted.empty()) wanted.erase(sector->logicalTrack,
{ sector->logicalSide,
Logger() << "missing sector on verify"; sector->logicalSector);
return false; }
} if (!wanted.empty())
{
Logger() << "missing sector on verify";
return false;
}
return true; return true;
}); });
} }
@@ -319,14 +338,14 @@ void writeDiskCommand(const Image& image,
AbstractDecoder* decoder, AbstractDecoder* decoder,
FluxSource* fluxSource) FluxSource* fluxSource)
{ {
const Image* imagep = &image; const Image* imagep = &image;
std::unique_ptr<const Image> remapped; std::unique_ptr<const Image> remapped;
if (config.has_sector_mapping()) if (config.has_sector_mapping())
{ {
remapped = Mapper::remapSectorsLogicalToPhysical( remapped = Mapper::remapSectorsLogicalToPhysical(
image, config.sector_mapping()); image, config.sector_mapping());
imagep = &*remapped; imagep = &*remapped;
} }
if (fluxSource && decoder) if (fluxSource && decoder)
writeTracksAndVerify(fluxSink, encoder, *fluxSource, *decoder, *imagep); writeTracksAndVerify(fluxSink, encoder, *fluxSource, *decoder, *imagep);
@@ -346,9 +365,8 @@ void writeRawDiskCommand(FluxSource& fluxSource, FluxSink& fluxSink)
dontVerify); dontVerify);
} }
std::shared_ptr<TrackFlux> readAndDecodeTrack(FluxSource& fluxSource, std::shared_ptr<TrackFlux> readAndDecodeTrack(
AbstractDecoder& decoder, FluxSource& fluxSource, AbstractDecoder& decoder, const Location& location)
const Location& location)
{ {
auto trackFlux = std::make_shared<TrackFlux>(); auto trackFlux = std::make_shared<TrackFlux>();
trackFlux->location = location; trackFlux->location = location;
@@ -378,7 +396,7 @@ std::shared_ptr<TrackFlux> readAndDecodeTrack(FluxSource& fluxSource,
retriesRemaining--; retriesRemaining--;
} }
return trackFlux; return trackFlux;
} }
std::shared_ptr<const DiskFlux> readDiskCommand( std::shared_ptr<const DiskFlux> readDiskCommand(
@@ -390,12 +408,18 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
auto diskflux = std::make_shared<DiskFlux>(); 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(); testForEmergencyStop();
auto trackFlux = readAndDecodeTrack( auto trackFlux = readAndDecodeTrack(fluxSource, decoder, location);
fluxSource, decoder, location);
diskflux->tracks.push_back(trackFlux); diskflux->tracks.push_back(trackFlux);
if (outputFluxSink) if (outputFluxSink)
@@ -478,6 +502,7 @@ std::shared_ptr<const DiskFlux> readDiskCommand(
/* diskflux can't be modified below this point. */ /* diskflux can't be modified below this point. */
Logger() << DiskReadLogMessage{diskflux}; Logger() << DiskReadLogMessage{diskflux};
Logger() << BeginOperationLogMessage{"Read complete"};
return diskflux; return diskflux;
} }
@@ -494,10 +519,20 @@ void readDiskCommand(
void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink) 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(); testForEmergencyStop();
auto fluxSourceIterator = fluxsource.readFlux(track, head); auto fluxSourceIterator = fluxsource.readFlux(track, head);
@@ -511,6 +546,8 @@ void rawReadDiskCommand(FluxSource& fluxsource, FluxSink& fluxsink)
fluxsink.writeFlux(track, head, *fluxmap); fluxsink.writeFlux(track, head, *fluxmap);
} }
} }
Logger() << EndOperationLogMessage{"Raw read complete"};
} }
void fillBitmapTo(std::vector<bool>& bitmap, void fillBitmapTo(std::vector<bool>& bitmap,

View File

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

View File

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

View File

@@ -481,6 +481,7 @@ public:
/* A fatal error. */ /* A fatal error. */
[&](const ErrorLogMessage& m) [&](const ErrorLogMessage& m)
{ {
_statusBar->SetLeftLabel(m.message);
wxMessageBox(m.message, "Error", wxOK | wxICON_ERROR); wxMessageBox(m.message, "Error", wxOK | wxICON_ERROR);
_state = _errorState; _state = _errorState;
UpdateState(); UpdateState();
@@ -523,6 +524,27 @@ public:
{ {
_currentDisk = m.disk; _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); *message);
} }