forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add api recording capability and fix getrequest (sonic-net#74)
* Handle default trap group and remove vlan members * Revert log level to notice * Add api recorder to sairedis * Use same asic view table for get request * Remove flush command from recording * Fix buffer size and handle SAI defines
- Loading branch information
Showing
13 changed files
with
173 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "sai_redis.h" | ||
|
||
std::string getTimestamp() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
char buffer[64]; | ||
struct timeval tv; | ||
|
||
gettimeofday(&tv, NULL); | ||
|
||
size_t size = strftime(buffer, 32 ,"%Y-%m-%d.%T.", localtime(&tv.tv_sec)); | ||
|
||
snprintf(&buffer[size], 32, "%06ld", tv.tv_usec); | ||
|
||
return std::string(buffer); | ||
} | ||
|
||
// currenly true by default for debugging | ||
volatile bool g_record = true; | ||
|
||
std::ofstream recording; | ||
|
||
void recordLine(std::string s) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (recording.is_open()) | ||
{ | ||
recording << getTimestamp() << "," << s << std::endl; | ||
} | ||
} | ||
|
||
std::string recfile = "dummy.rec"; | ||
|
||
void startRecording() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
recfile = "sairedis." + getTimestamp() + ".rec"; | ||
|
||
recording.open(recfile); | ||
|
||
if (!recording.is_open()) | ||
{ | ||
SWSS_LOG_ERROR("failed to open recording file %s: %s", recfile.c_str(), strerror(errno)); | ||
return; | ||
} | ||
|
||
recordLine("#,recording on: " + recfile); | ||
|
||
SWSS_LOG_NOTICE("started recording: %s", recfile.c_str()); | ||
} | ||
|
||
void stopRecording() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (recording.is_open()) | ||
{ | ||
recording.close(); | ||
|
||
SWSS_LOG_NOTICE("stopped recording: %s", recfile.c_str()); | ||
} | ||
} | ||
|
||
void setRecording(bool record) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
g_record = record; | ||
|
||
stopRecording(); | ||
|
||
if (record) | ||
{ | ||
startRecording(); | ||
} | ||
} | ||
|
||
std::string joinFieldValues( | ||
_In_ const std::vector<swss::FieldValueTuple> &values) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
std::stringstream ss; | ||
|
||
for (size_t i = 0; i < values.size(); ++i) | ||
{ | ||
const std::string &str_attr_id = fvField(values[i]); | ||
const std::string &str_attr_value = fvValue(values[i]); | ||
|
||
if(i != 0) | ||
{ | ||
ss << ","; | ||
} | ||
|
||
ss << str_attr_id << "=" << str_attr_value; | ||
} | ||
|
||
return ss.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters