-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 10, 2024
1 parent
1423707
commit 601d885
Showing
6 changed files
with
186 additions
and
13 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,65 @@ | ||
#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 std::format("RollingLogFollow, got {} connections", socketToRollingLogFollowQueue.size()); | ||
} | ||
|
||
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] = std::format("[LOG] Following log to socket: {} started\n", socket); | ||
running = true; | ||
} | ||
|
||
static RollingLogFollow& Get() { | ||
static RollingLogFollow instance; | ||
static std::mutex gm; | ||
std::lock_guard<std::mutex> lock(gm); | ||
return instance; | ||
}; | ||
}; | ||
} |