mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-01 19:41:48 +00:00
Make enum names more unique, extend statistics
This commit is contained in:
parent
8ddd95d118
commit
bd5e6ad428
|
@ -731,7 +731,7 @@ vector<PbStatistics> Disk::GetStatistics() const
|
|||
s.set_id(GetId());
|
||||
s.set_unit(GetLun());
|
||||
|
||||
s.set_category(PbStatisticsCategory::INFO);
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_INFO);
|
||||
|
||||
s.set_key(SECTOR_READ_COUNT);
|
||||
s.set_value(sector_read_count);
|
||||
|
|
|
@ -195,7 +195,7 @@ vector<PbStatistics> DiskCache::GetStatistics(bool is_read_only) const
|
|||
|
||||
PbStatistics s;
|
||||
|
||||
s.set_category(PbStatisticsCategory::INFO);
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_INFO);
|
||||
|
||||
s.set_key(CACHE_MISS_READ_COUNT);
|
||||
s.set_value(cache_miss_read_count);
|
||||
|
@ -207,7 +207,7 @@ vector<PbStatistics> DiskCache::GetStatistics(bool is_read_only) const
|
|||
statistics.push_back(s);
|
||||
}
|
||||
|
||||
s.set_category(PbStatisticsCategory::ERROR);
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_ERROR);
|
||||
|
||||
s.set_key(READ_ERROR_COUNT);
|
||||
s.set_value(read_error_count);
|
||||
|
|
|
@ -490,7 +490,7 @@ vector<PbStatistics> SCSIDaynaPort::GetStatistics() const
|
|||
s.set_id(GetId());
|
||||
s.set_unit(GetLun());
|
||||
|
||||
s.set_category(PbStatisticsCategory::INFO);
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_INFO);
|
||||
|
||||
s.set_key(BYTE_READ_COUNT);
|
||||
s.set_value(byte_read_count);
|
||||
|
|
|
@ -94,6 +94,8 @@ void SCSIPrinter::Print()
|
|||
LogError("Transfer buffer overflow: Buffer size is " + to_string(GetController()->GetBuffer().size()) +
|
||||
" bytes, " + to_string(length) + " bytes expected");
|
||||
|
||||
++print_error_count;
|
||||
|
||||
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_cdb);
|
||||
}
|
||||
|
||||
|
@ -108,6 +110,8 @@ void SCSIPrinter::SynchronizeBuffer()
|
|||
if (!out.is_open()) {
|
||||
LogWarn("Nothing to print");
|
||||
|
||||
++print_warning_count;
|
||||
|
||||
throw scsi_exception(sense_key::aborted_command);
|
||||
}
|
||||
|
||||
|
@ -124,6 +128,8 @@ void SCSIPrinter::SynchronizeBuffer()
|
|||
if (system(cmd.c_str())) {
|
||||
LogError("Printing file '" + filename + "' failed, the printing system might not be configured");
|
||||
|
||||
++print_error_count;
|
||||
|
||||
CleanUp();
|
||||
|
||||
throw scsi_exception(sense_key::aborted_command);
|
||||
|
@ -136,6 +142,8 @@ void SCSIPrinter::SynchronizeBuffer()
|
|||
|
||||
bool SCSIPrinter::WriteByteSequence(span<const uint8_t> buf)
|
||||
{
|
||||
byte_receive_count += buf.size();
|
||||
|
||||
if (!out.is_open()) {
|
||||
vector<char> f(file_template.begin(), file_template.end());
|
||||
f.push_back(0);
|
||||
|
@ -144,6 +152,9 @@ bool SCSIPrinter::WriteByteSequence(span<const uint8_t> buf)
|
|||
const int fd = mkstemp(f.data());
|
||||
if (fd == -1) {
|
||||
LogError("Can't create printer output file for pattern '" + filename + "': " + strerror(errno));
|
||||
|
||||
++print_error_count;
|
||||
|
||||
return false;
|
||||
}
|
||||
close(fd);
|
||||
|
@ -152,6 +163,8 @@ bool SCSIPrinter::WriteByteSequence(span<const uint8_t> buf)
|
|||
|
||||
out.open(filename, ios::binary);
|
||||
if (out.fail()) {
|
||||
++print_error_count;
|
||||
|
||||
throw scsi_exception(sense_key::aborted_command);
|
||||
}
|
||||
|
||||
|
@ -162,7 +175,12 @@ bool SCSIPrinter::WriteByteSequence(span<const uint8_t> buf)
|
|||
|
||||
out.write((const char *)buf.data(), buf.size());
|
||||
|
||||
return !out.fail();
|
||||
const bool status = out.fail();
|
||||
if (!status) {
|
||||
++print_error_count;
|
||||
}
|
||||
|
||||
return !status;
|
||||
}
|
||||
|
||||
void SCSIPrinter::CleanUp()
|
||||
|
@ -187,11 +205,27 @@ vector<PbStatistics> SCSIPrinter::GetStatistics() const
|
|||
s.set_id(GetId());
|
||||
s.set_unit(GetLun());
|
||||
|
||||
s.set_category(PbStatisticsCategory::INFO);
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_INFO);
|
||||
|
||||
s.set_key(FILE_PRINT_COUNT);
|
||||
s.set_value(file_print_count);
|
||||
statistics.push_back(s);
|
||||
|
||||
s.set_key(BYTE_RECEIVE_COUNT);
|
||||
s.set_value(byte_receive_count);
|
||||
statistics.push_back(s);
|
||||
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_ERROR);
|
||||
|
||||
s.set_key(PRINT_ERROR_COUNT);
|
||||
s.set_value(print_error_count);
|
||||
statistics.push_back(s);
|
||||
|
||||
s.set_category(PbStatisticsCategory::CATEGORY_WARNING);
|
||||
|
||||
s.set_key(PRINT_WARNING_COUNT);
|
||||
s.set_value(print_warning_count);
|
||||
statistics.push_back(s);
|
||||
|
||||
return statistics;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,18 @@ using namespace std;
|
|||
class SCSIPrinter : public PrimaryDevice, private ScsiPrinterCommands
|
||||
{
|
||||
uint64_t file_print_count = 0;
|
||||
uint64_t byte_receive_count = 0;
|
||||
uint64_t print_error_count = 0;
|
||||
uint64_t print_warning_count = 0;
|
||||
|
||||
static const int NOT_RESERVED = -2;
|
||||
|
||||
static constexpr const char *PRINTER_FILE_PATTERN = "/piscsi_sclp-XXXXXX";
|
||||
|
||||
inline static const string FILE_PRINT_COUNT = "file_print_count";
|
||||
inline static const string BYTE_RECEIVE_COUNT = "byte_receive_count";
|
||||
inline static const string PRINT_ERROR_COUNT = "print_error_count";
|
||||
inline static const string PRINT_WARNING_COUNT = "print_warning_count";
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -319,10 +319,10 @@ message PbNetworkInterfacesInfo {
|
|||
|
||||
// Statistics categories ordered by increasing severity
|
||||
enum PbStatisticsCategory {
|
||||
NO_CATEGORY = 0;
|
||||
INFO = 1;
|
||||
WARNING = 2;
|
||||
ERROR = 3;
|
||||
CATEGORY_NONE = 0;
|
||||
CATEGORY_INFO = 1;
|
||||
CATEGORY_WARNING = 2;
|
||||
CATEGORY_ERROR = 3;
|
||||
}
|
||||
|
||||
message PbStatistics {
|
||||
|
@ -331,15 +331,18 @@ message PbStatistics {
|
|||
int32 id = 2;
|
||||
int32 unit = 3;
|
||||
// A symbolic unique item name, may be used for I18N. Supported values and their categories:
|
||||
// "read_error_count" (ERROR)
|
||||
// "write_error_count" (ERROR)
|
||||
// "cache_miss_read_count" (INFO)
|
||||
// "cache_miss_write_count" (INFO)
|
||||
// "sector_read_count" (INFO)
|
||||
// "sector_write_count" (INFO)
|
||||
// "read_error_count" (ERROR, SCHD/SCRM/SCMO/SCCD)
|
||||
// "write_error_count" (ERROR, SCHD/SCRM/SCMO)
|
||||
// "cache_miss_read_count" (INFO, SCHD/SCRM/SCMO/SCCD)
|
||||
// "cache_miss_write_count" (INFO, SCHD/SCRM/SCMO)
|
||||
// "sector_read_count" (INFO, SCHD/SCRM/SCMO/SCCD)
|
||||
// "sector_write_count" (INFO, SCHD/SCRM/SCMO)
|
||||
// "byte_read_count" (INFO, SCDP)
|
||||
// "byte_write_count" (INFO, SCDP)
|
||||
// "print_error_count" (ERROR, SCLP)
|
||||
// "print_warning_count" (WARNING, SCLP)
|
||||
// "file_print_count" (INFO, SCLP)
|
||||
// "byte_receive_count" (INFO, SCLP)
|
||||
string key = 4;
|
||||
uint64 value = 5;
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ string ScsictlDisplay::DisplayStatisticsInfo(const PbStatisticsInfo& statistics_
|
|||
return a.key() < b.key();
|
||||
});
|
||||
|
||||
PbStatisticsCategory prev_category = PbStatisticsCategory::NO_CATEGORY;
|
||||
PbStatisticsCategory prev_category = PbStatisticsCategory::CATEGORY_NONE;
|
||||
for (const auto& statistics : sorted_statistics) {
|
||||
if (statistics.category() != prev_category) {
|
||||
s << " " << PbStatisticsCategory_Name(statistics.category()) << '\n';
|
||||
|
|
Loading…
Reference in New Issue
Block a user