Skip to content

Commit

Permalink
Extend statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Oct 5, 2023
1 parent 52007ff commit 1810b2a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
14 changes: 11 additions & 3 deletions cpp/devices/disk_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,16 @@ bool DiskCache::Load(int index, int track, shared_ptr<DiskTrack> disktrk)
sectors = 0x100;
}

// Create a disk track
if (disktrk == nullptr) {
disktrk = make_shared<DiskTrack>();
}

// Initialize disk track
disktrk->Init(track, sec_size, sectors, cd_raw, imgoffset);

// Try loading
if (!disktrk->Load(sec_path)) {
// Failure
++read_error_count;

return false;
}

Expand All @@ -190,3 +189,12 @@ void DiskCache::UpdateSerialNumber()
}
}

statistics_map DiskCache::GetStatistics()
{
statistics_map statistics;

statistics.emplace(PbStatisticsCategory::ERROR, make_pair(READ_ERROR_COUNT, read_error_count));
statistics.emplace(PbStatisticsCategory::ERROR, make_pair(WRITE_ERROR_COUNT, write_error_count));

return statistics;
}
9 changes: 7 additions & 2 deletions cpp/devices/disk_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class DiskCache
// Number of tracks to cache
static const int CACHE_MAX = 16;

inline static uint32_t read_error_count = 0;
inline static uint32_t write_error_count = 0;

inline static const string READ_ERROR_COUNT = "read_error_count";
inline static const string WRITE_ERROR_COUNT = "write_error_count";

public:

// Internal data definition
Expand All @@ -40,12 +46,11 @@ class DiskCache

void SetRawMode(bool b) { cd_raw = b; } // CD-ROM raw mode setting

// Access
bool Save() const; // Save and release all
bool ReadSector(span<uint8_t>, uint32_t); // Sector Read
bool WriteSector(span<const uint8_t>, uint32_t); // Sector Write

static statistics_map GetStatistics() { return DiskTrack::GetStatistics(); }
static statistics_map GetStatistics();

private:

Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/disk_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class DiskTrack
DiskTrack(DiskTrack&) = delete;
DiskTrack& operator=(const DiskTrack&) = delete;

static statistics_map GetStatistics();

private:

friend class DiskCache;
Expand All @@ -68,6 +70,4 @@ class DiskTrack
bool WriteSector(span<const uint8_t> buf, int); // Sector Write

int GetTrack() const { return dt.track; } // Get track

static statistics_map GetStatistics();
};
3 changes: 2 additions & 1 deletion cpp/piscsi/statistics_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

statistics_map StatisticsCollector::GetStatistics() const
{
statistics_map statistics = Disk::GetStatistics();
statistics_map statistics = DiskTrack::GetStatistics();
statistics.merge(DiskCache::GetStatistics());
statistics.merge(Disk::GetStatistics());

return statistics;
}

0 comments on commit 1810b2a

Please sign in to comment.