forked from sonic-net/sonic-sairedis
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sequencer class with lambda response message #2
Open
DanielaMurin
wants to merge
38
commits into
master
Choose a base branch
from
syncd_multithread
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b30be88
Sequencer class with lambda response message
DanielaMurin d0369a2
Add Sequencer to sendGetResponse
DanielaMurin 2caeedc
Ring Buffer - Phase 1: The main thread push to the ring buffer and th…
shiraez 98c6c89
Remove singleton & fix compilation
DanielaMurin 78ec4a7
Fix merge issues
DanielaMurin 65f94df
add debug info + enable thread
shiraez 8523a2a
add delay
shiraez 0ddc1ec
debug single ring buffer & enable sequencer
DanielaMurin cc73b2e
Add new debug file & move sequencer alloc to processEvent
DanielaMurin c1b916a
fix reset sequencer logic
DanielaMurin 8d0feae
Take out lambda execute from within lock
DanielaMurin efc1bc9
add loger
shiraez da6d6b9
Merge branch 'syncd_multithread' of https://github.com/Marvell-switch…
shiraez 5e2e15c
Working single ring buffer & sequencer
DanielaMurin fdf56c9
Merge branch 'syncd_multithread' of https://github.com/Marvell-switch…
shiraez d3fddf3
add logger to syncd + sequencer
shiraez 9b01706
Return m_switches and m_mdioIpcServer logic
DanielaMurin 7a14462
fix Logger
shiraez b4d0a06
Merge branch 'syncd_multithread' of https://github.com/Marvell-switch…
shiraez 04eb362
add logger.h file
shiraez 00b8ade
Update sequencer statistics/mux/logging
DanielaMurin 94005f8
Merge conflict fix, remove old logger code
DanielaMurin 3f121a3
enable flag to the logger
shiraez 7a661ce
Return diag shell thread, improve lambda func readability
DanielaMurin 8ea0eb6
Allocate sequence number inside functions
DanielaMurin 9908e23
add multiRing buffer support & send response for all ops
aviramd 328867e
fix find operation group by string
aviramd 762ae3b
fix find ring buffer by op or objectType
aviramd a5d4802
fix sendApiResponse objectCount param on processBulkQuadEventInInitVi…
aviramd b10bf7d
removing unnecessary code
shiraez 0225abc
Fix send responde sync for nom get actions
aviramd 6cf0e13
create muliple threads, cleanup, change response seq order
aviramd a2d711e
Sequencer update & Cleanup
DanielaMurin 4c72076
Sequencer update - ring buffer instead of map
DanielaMurin c5e511a
fix bug when redis reads empty key
aviramd db71e99
REVERT - Sequencer update - ring buffer instead of map
DanielaMurin d52b04e
protected RedisClient + RedisSelectableChannel
shiraez cad2dcb
remove LOCK from loop wrap it instead , add thread id prints, 3 threads
aviramd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#ifndef LOGGER_H | ||
#define LOGGER_H | ||
|
||
#define MODULE_NAME "syncd" | ||
|
||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <sys/stat.h> | ||
#include <chrono> | ||
#include <cstdio> | ||
#include <mutex> | ||
#include <sstream> | ||
#include <iomanip> | ||
#include "fmt/format.h" | ||
#include <ctime> | ||
#include <thread> | ||
|
||
#define MAX_LOG_SIZE (10 *50 * 1024) /* 50 KB */ | ||
#define ENABLE_LOGGING 1 | ||
|
||
// Define a mutex for thread safety | ||
static std::mutex logMutex; | ||
|
||
// Improved logging function with thread safety | ||
static void writeToLogFile(const std::string& funcName, const std::string& fileNum, const std::string& message) { | ||
// Lock the mutex to ensure thread safety | ||
std::lock_guard<std::mutex> lock(logMutex); | ||
|
||
std::string filePath = "/" + std::string(MODULE_NAME) + "_debugLog_" + fileNum + ".txt"; | ||
std::string backupFilePath = filePath + ".history"; | ||
struct stat fileStat; | ||
|
||
// Check if the log file exists and if its size exceeds the maximum limit | ||
if (stat(filePath.c_str(), &fileStat) == 0) { | ||
if (fileStat.st_size > MAX_LOG_SIZE) { | ||
// Remove the old backup file | ||
std::remove(backupFilePath.c_str()); | ||
// Rename the current log file to the backup file | ||
if (std::rename(filePath.c_str(), backupFilePath.c_str()) != 0) { | ||
std::cerr << "Error: Could not rename file " << filePath << " to " << backupFilePath << std::endl; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// Open the log file in append mode | ||
std::ofstream logFile(filePath, std::ios_base::app); | ||
if (!logFile.is_open()) { | ||
std::cerr << "Error: Could not open file " << filePath << std::endl; | ||
return; | ||
} | ||
|
||
auto now = std::chrono::system_clock::now(); | ||
auto in_time_t = std::chrono::system_clock::to_time_t(now); | ||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000; | ||
|
||
std::ostringstream oss; | ||
oss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %H:%M:%S") | ||
<< '.' << std::setw(3) << std::setfill('0') << milliseconds.count(); | ||
std::string formatted_time = oss.str(); | ||
|
||
std::thread::id this_id = std::this_thread::get_id(); | ||
|
||
// Write the timestamp, function name, and message to the log file | ||
logFile << formatted_time << " V4 " << this_id << " " << funcName << ": " << message << std::endl; | ||
|
||
|
||
logFile.close(); | ||
} | ||
|
||
template<typename... Args> | ||
static void logFormattedMessage(const std::string& funcName, const std::string& fileNum, const std::string& format, Args... messageArgs) { | ||
std::ostringstream oss; | ||
|
||
std::string remainingFormat = format; | ||
|
||
// Helper function to process a single argument | ||
auto processArg = [&oss, &remainingFormat](const auto& arg) { | ||
size_t pos = remainingFormat.find("{}"); | ||
if (pos != std::string::npos) { | ||
oss << remainingFormat.substr(0, pos) << arg; | ||
remainingFormat = remainingFormat.substr(pos + 2); | ||
} | ||
}; | ||
|
||
// Helper function to recursively process all arguments | ||
auto processAllArgs = [&](auto&&... innerArgs) -> void { | ||
(void)std::initializer_list<int>{(processArg(innerArgs), 0)...}; | ||
}; | ||
|
||
// Process all arguments | ||
processAllArgs(messageArgs...); | ||
|
||
// Add any remaining format string | ||
oss << remainingFormat; | ||
|
||
// Write the full message to the log file | ||
writeToLogFile(funcName, fileNum, oss.str()); | ||
} | ||
#if ENABLE_LOGGING | ||
// Macro for easy logging with formatting | ||
#define LogToModuleFile(fileNum, format, ...) logFormattedMessage(__func__, fileNum, format, ##__VA_ARGS__) | ||
#else | ||
#define LogToModuleFile(fileNum, format, ...) | ||
#endif | ||
|
||
#endif // LOGGER_H |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is ring buffer not here ?