-
-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [hyprctl, core] added --follow option to rolliglog
- Loading branch information
Крылов Александр
committed
Jun 7, 2024
1 parent
0ebb43c
commit 804840c
Showing
6 changed files
with
184 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <shared_mutex> | ||
|
||
namespace Debug { | ||
struct RollingLogFollow { | ||
std::unordered_map<int, std::string> socketToRollingLogFollowQueue; | ||
std::shared_mutex m; | ||
bool running = false; | ||
static constexpr size_t ROLLING_LOG_FOLLOW_TOO_BIG = 8192; | ||
|
||
// Returns true if the queue is empty for the given socket | ||
bool isEmpty(int socket) { | ||
std::shared_lock<std::shared_mutex> r(m); | ||
return socketToRollingLogFollowQueue[socket].empty(); | ||
} | ||
|
||
std::string DebugInfo() { | ||
std::shared_lock<std::shared_mutex> r(m); | ||
return "RollingLogFollow, got " + std::to_string(socketToRollingLogFollowQueue.size()) + " connections"; | ||
} | ||
|
||
std::string GetLog(int socket) { | ||
std::unique_lock<std::shared_mutex> w(m); | ||
|
||
const std::string ret = socketToRollingLogFollowQueue[socket]; | ||
socketToRollingLogFollowQueue[socket] = ""; | ||
|
||
return ret; | ||
}; | ||
|
||
void AddLog(std::string log) { | ||
std::unique_lock<std::shared_mutex> w(m); | ||
running = true; | ||
std::vector<int> to_erase; | ||
for (const auto& p : socketToRollingLogFollowQueue) | ||
socketToRollingLogFollowQueue[p.first] += log + "\n"; | ||
} | ||
|
||
bool IsRunning() { | ||
std::shared_lock<std::shared_mutex> r(m); | ||
return running; | ||
} | ||
|
||
void StopFor(int socket) { | ||
std::unique_lock<std::shared_mutex> w(m); | ||
socketToRollingLogFollowQueue.erase(socket); | ||
if (socketToRollingLogFollowQueue.empty()) | ||
running = false; | ||
} | ||
void StartFor(int socket) { | ||
std::unique_lock<std::shared_mutex> w(m); | ||
socketToRollingLogFollowQueue[socket] = "[LOG] Following log to socket: " + std::to_string(socket) + " started" + "\n"; | ||
running = true; | ||
} | ||
static RollingLogFollow& Get() { | ||
static RollingLogFollow instance; | ||
static std::mutex gm; | ||
std::lock_guard<std::mutex> lock(gm); | ||
return instance; | ||
}; | ||
}; | ||
} |