Skip to content

Commit

Permalink
fix loading from log
Browse files Browse the repository at this point in the history
Summary: Title

Differential Revision: D64738480

fbshipit-source-id: c8d93536fab44829b78fbcaa113fb814386721f2
  • Loading branch information
Mohammed Al-Sanabani authored and facebook-github-bot committed Nov 16, 2024
1 parent ab5de44 commit 64680b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
43 changes: 21 additions & 22 deletions fboss/qsfp_service/module/I2cLogBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,38 +280,37 @@ std::pair<size_t, size_t> I2cLogBuffer::dumpToFile() {
return std::make_pair(hdrSize, logCount);
}

TransceiverAccessParameter I2cLogBuffer::getParam(std::stringstream& ss) {
TransceiverAccessParameter I2cLogBuffer::getParam(const std::string& str) {
TransceiverAccessParameter param(0, 0, 0);
std::string token;
ss >> token;
if (token != kEmptyOptional) {
param.i2cAddress = folly::to<uint8_t>(token);
std::vector<std::string> fields;
folly::split(' ', str, fields, true);
if (fields.size() < kNumParamFields) {
throw std::out_of_range("Invalie param fields:" + str);
}
ss >> token;
if (token != kEmptyOptional) {
param.page = folly::to<uint8_t>(token);
if (fields.at(0) != kEmptyOptional) {
param.i2cAddress = folly::to<uint8_t>(fields.at(0));
};
if (fields.at(1) != kEmptyOptional) {
param.page = folly::to<int>(fields.at(1));
}
ss >> token;
if (token != kEmptyOptional) {
param.bank = folly::to<uint8_t>(token);
if (fields.at(2) != kEmptyOptional) {
param.bank = folly::to<int>(fields.at(2));
}
ss >> param.offset;
ss >> param.len;
param.offset = folly::to<int>(fields.at(3));
param.len = folly::to<int>(fields.at(4));
return param;
}

I2cLogBuffer::Operation I2cLogBuffer::getOp(std::stringstream& ss) {
char c;
ss >> c;
switch (c) {
I2cLogBuffer::Operation I2cLogBuffer::getOp(const char op) {
switch (op) {
case 'R':
return Operation::Read;
break;
case 'W':
return Operation::Write;
break;
default:
throw std::invalid_argument(fmt::format("Invalid Operation :{}", c));
throw std::invalid_argument(fmt::format("Invalid Operation :{}", op));
break;
}
}
Expand Down Expand Up @@ -379,10 +378,10 @@ std::vector<I2cLogBuffer::I2cReplayEntry> I2cLogBuffer::loadFromLog(
}

while (std::getline(file, line)) {
ss = std::stringstream(getField(line, '<', '>'));
auto param = getParam(ss);
auto op = getOp(ss);
auto str = getField(line, '[', ']');
auto str = getField(line, '<', '>');
auto param = getParam(str);
auto op = getOp(str.back());
str = getField(line, '[', ']');
auto data = getData(str);
auto delay = getDelay(line);
str = getField(line, '>', '[');
Expand Down
7 changes: 5 additions & 2 deletions fboss/qsfp_service/module/I2cLogBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace facebook::fboss {
constexpr int kMaxI2clogDataSize = 128;
constexpr size_t kI2cFieldNameLength = 16;

// Number of address fields in TransceiverAccessParameter
constexpr int kNumParamFields = 5;

class I2cLogBuffer {
using TimePointSteady = std::chrono::steady_clock::time_point;
using TimePointSystem = std::chrono::system_clock::time_point;
Expand Down Expand Up @@ -176,8 +179,8 @@ class I2cLogBuffer {
// Operations to re-construct I2cReplayEntry from a log file.
static size_t getHeader(std::stringstream& ss, const I2cLogHeader& info);
static std::string getField(const std::string& line, char left, char right);
static TransceiverAccessParameter getParam(std::stringstream& ss);
static I2cLogBuffer::Operation getOp(std::stringstream& ss);
static TransceiverAccessParameter getParam(const std::string& str);
static I2cLogBuffer::Operation getOp(const char op);
static std::array<uint8_t, kMaxI2clogDataSize> getData(std::string str);
static uint64_t getDelay(const std::string& str);
static bool getSuccess(const std::string& str);
Expand Down

0 comments on commit 64680b1

Please sign in to comment.