Skip to content

Commit

Permalink
Add StatisticsCollector class
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Oct 5, 2023
1 parent 754ff4d commit 792d3a3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 0 additions & 2 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,5 @@ statistics_map Disk::GetStatistics()
statistics.emplace(PbStatisticsCategory::INFO, make_pair(SECTOR_READ_COUNT, sector_read_count));
statistics.emplace(PbStatisticsCategory::INFO, make_pair(SECTOR_WRITE_COUNT, sector_write_count));

statistics.merge(DiskCache::GetStatistics());

return statistics;
}
2 changes: 1 addition & 1 deletion cpp/piscsi/piscsi_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void PiscsiResponse::GetMappingInfo(PbMappingInfo& mapping_info) const

void PiscsiResponse::GetStatisticsInfo(PbStatisticsInfo& statistics_info) const
{
for (const auto& [category, item] : Disk::GetStatistics()) {
for (const auto& [category, item] : collector.GetStatistics()) {
auto statistics = statistics_info.add_statistics();
statistics->set_category(category);
statistics->set_key(item.first);
Expand Down
3 changes: 3 additions & 0 deletions cpp/piscsi/piscsi_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "devices/device_factory.h"
#include "devices/primary_device.h"
#include "piscsi/statistics_collector.h"
#include "generated/piscsi_interface.pb.h"
#include <string>
#include <span>
Expand Down Expand Up @@ -47,6 +48,8 @@ class PiscsiResponse

const DeviceFactory device_factory;

const StatisticsCollector collector;

void GetDeviceProperties(const Device&, PbDeviceProperties&) const;
void GetDevice(const Device&, PbDevice&, const string&) const;
void GetDeviceTypeProperties(PbDeviceTypesInfo&, PbDeviceType) const;
Expand Down
18 changes: 18 additions & 0 deletions cpp/piscsi/statistics_collector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2023 Uwe Seimet
//
//---------------------------------------------------------------------------

#include "statistics_collector.h"

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

return statistics;
}
23 changes: 23 additions & 0 deletions cpp/piscsi/statistics_collector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2023 Uwe Seimet
//
//---------------------------------------------------------------------------

#pragma once

#include "devices/disk.h"

class StatisticsCollector
{

public:

StatisticsCollector() = default;
~StatisticsCollector() = default;

statistics_map GetStatistics() const;
};

0 comments on commit 792d3a3

Please sign in to comment.