Skip to content

Commit

Permalink
Fix recording logic (sonic-net#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and Shuotian Cheng committed Oct 26, 2016
1 parent 391ed8e commit 5c9d854
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/src/sai_redis_generic_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sai_status_t internal_redis_generic_create(

if (g_record)
{
recordLine("c," + key + "," + joinFieldValues(entry));
recordLine("c|" + key + "|" + joinFieldValues(entry));
}

g_asicState->set(key, entry, "create");
Expand Down
6 changes: 3 additions & 3 deletions lib/src/sai_redis_generic_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sai_status_t internal_redis_generic_get(

if (g_record)
{
recordLine("g," + key + "," + joinFieldValues(entry));
recordLine("g|" + key + "|" + joinFieldValues(entry));
}

// get is special, it will not put data
Expand Down Expand Up @@ -116,7 +116,7 @@ sai_status_t internal_redis_generic_get(
const std::vector<swss::FieldValueTuple> &values = kfvFieldsValues(kco);

// first serialized is status
recordLine("G," + str_status + "," + joinFieldValues(values));
recordLine("G|" + str_status + "|" + joinFieldValues(values));
}

SWSS_LOG_DEBUG("generic get status: %d", status);
Expand All @@ -130,7 +130,7 @@ sai_status_t internal_redis_generic_get(

if (g_record)
{
recordLine("G,FAILURE");
recordLine("G|SAI_STATUS_FAILURE");
}

SWSS_LOG_ERROR("generic get failed to get response");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sai_redis_generic_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sai_status_t internal_redis_generic_remove(

if (g_record)
{
recordLine("r," + key);
recordLine("r|" + key);
}

g_asicState->del(key, "remove");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sai_redis_generic_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sai_status_t internal_redis_generic_set(

if (g_record)
{
recordLine("s," + key + "," + joinFieldValues(entry));
recordLine("s|" + key + "|" + joinFieldValues(entry));
}

g_asicState->set(key, entry, "set");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sai_redis_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void handle_notification(

if (g_record)
{
recordLine("n," + notification + "," + data + "," + joinFieldValues(values));
recordLine("n|" + notification + "|" + data + "|" + joinFieldValues(values));
}

if (notification == "switch_state_change")
Expand Down
6 changes: 3 additions & 3 deletions lib/src/sai_redis_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void recordLine(std::string s)

if (recording.is_open())
{
recording << getTimestamp() << "," << s << std::endl;
recording << getTimestamp() << "|" << s << std::endl;
}
}

Expand All @@ -48,7 +48,7 @@ void startRecording()
return;
}

recordLine("#,recording on: " + recfile);
recordLine("#|recording on: " + recfile);

SWSS_LOG_NOTICE("started recording: %s", recfile.c_str());
}
Expand Down Expand Up @@ -93,7 +93,7 @@ std::string joinFieldValues(

if(i != 0)
{
ss << ",";
ss << "|";
}

ss << str_attr_id << "=" << str_attr_value;
Expand Down
35 changes: 19 additions & 16 deletions player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,17 @@ const std::vector<swss::FieldValueTuple> get_values(const std::vector<std::strin
{
std::vector<swss::FieldValueTuple> values;

// timestamp,action,objecttype:objectid,attrid=value,...
// timestamp|action|objecttype:objectid|attrid=value,...
for (size_t i = 3; i <items.size(); ++i)
{
auto o = swss::tokenize(items[i], '=');
const std::string& item = items[i];

swss::FieldValueTuple entry(o[0], o[1]);
auto start = item.find_first_of("=");

auto field = item.substr(0, start);
auto value = item.substr(start + 1);

swss::FieldValueTuple entry(field, value);

values.push_back(entry);
}
Expand Down Expand Up @@ -921,11 +926,8 @@ void handle_get_response(

//std::cout << "processing " << response << std::endl;

// timestamp,action,objecttype:objectid,attrid=value,...
auto v = swss::tokenize(response, ',');

// objecttype:objectid
auto o = swss::tokenize(v[2], ':');
// timestamp|action|objecttype:objectid|attrid=value,...
auto v = swss::tokenize(response, '|');

auto values = get_values(v);

Expand Down Expand Up @@ -972,7 +974,7 @@ int replay(int argc, char **argv)

sai_common_api_t api = SAI_COMMON_API_CREATE;

auto p = line.find_first_of(",");
auto p = line.find_first_of("|");

char op = line[p+1];

Expand All @@ -999,15 +1001,16 @@ int replay(int argc, char **argv)
exit(EXIT_FAILURE);
}

// timestamp,action,objecttype:objectid,attrid=value,...
auto fields = swss::tokenize(line, ',');
// timestamp|action|objecttype:objectid|attrid=value,...
auto fields = swss::tokenize(line, '|');

// objecttype:objectid
auto o = swss::tokenize(fields[2], ':');
// objecttype:objectid (object id may contain ':')
auto start = fields[2].find_first_of(":");

sai_object_type_t object_type = deserialize_object_type(o[0]);
auto str_object_type = fields[2].substr(0, start);
auto str_object_id = fields[2].substr(start + 1);

const std::string& str_object_id = o[1];
sai_object_type_t object_type = deserialize_object_type(str_object_type);

auto values = get_values(fields);

Expand Down Expand Up @@ -1073,7 +1076,7 @@ int replay(int argc, char **argv)
// this line may be notification, we need to skip
std::getline(infile, response);
}
while (response[response.find_first_of(",")+1] == 'n');
while (response[response.find_first_of("|")+1] == 'n');

handle_get_response(object_type, attr_count, attr_list, response);
}
Expand Down
2 changes: 1 addition & 1 deletion syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to create object %llx: %d", objectType, status);
SWSS_LOG_ERROR("failed to create object %s: %s", sai_serialize_object_type(objectType).c_str(), sai_serialize_status(status).c_str());

exit_and_notify(EXIT_FAILURE);
}
Expand Down

0 comments on commit 5c9d854

Please sign in to comment.