Skip to content

Commit

Permalink
move client from daemon specific client to generic client
Browse files Browse the repository at this point in the history
Summary:
I wanna log the client for all requests so we can get a better understanding of
Watchman clients. So I am gonna want the pid for all clients not just daemon
clients.

Moving the pid into the generic client class (from the daemon client class
where it is now) so I can use the pid in all cases.

Reviewed By: MichaelCuevas

Differential Revision: D61480179

fbshipit-source-id: b9f44209063bae373bf1e1f54b7354dd2f0c791c
  • Loading branch information
Katie Mancini authored and facebook-github-bot committed Aug 22, 2024
1 parent d4bf5dc commit 463d38c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
23 changes: 8 additions & 15 deletions watchman/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Client::Client(std::unique_ptr<watchman_stream> stm)
#else
w_event_make_sockets()
#endif
) {
),
peerPid_{this->stm->getPeerProcessID()},
peerInfo_{lookupProcessInfo(peerPid_)} {
logf(DBG, "accepted client:stm={}\n", fmt::ptr(this->stm.get()));
}

Expand Down Expand Up @@ -169,8 +171,7 @@ bool Client::dispatchCommand(const Command& command, CommandFlags mode) {
if (sample.finish()) {
sample.add_meta("args", std::move(rendered));
sample.add_meta(
"client",
json_object({{"pid", json_integer(stm->getPeerProcessID())}}));
"client", json_object({{"pid", json_integer(peerPid_)}}));
sample.log();
}

Expand All @@ -181,7 +182,7 @@ bool Client::dispatchCommand(const Command& command, CommandFlags mode) {
dispatchCommand.meta.base.event_count =
eventCount != samplingRate ? 0 : eventCount;
dispatchCommand.args = renderedString;
dispatchCommand.client_pid = stm->getPeerProcessID();
dispatchCommand.client_pid = peerPid_;
getLogger()->logEvent(dispatchCommand);
}

Expand Down Expand Up @@ -238,10 +239,7 @@ void UserClient::create(std::unique_ptr<watchman_stream> stm) {
}

UserClient::UserClient(PrivateBadge, std::unique_ptr<watchman_stream> stm)
: Client{std::move(stm)},
since_{std::chrono::system_clock::now()},
peerPid_{this->stm->getPeerProcessID()},
peerInfo_{lookupProcessInfo(peerPid_)} {
: Client{std::move(stm)}, since_{std::chrono::system_clock::now()} {
clients.wlock()->insert(this);
}

Expand Down Expand Up @@ -321,12 +319,7 @@ void UserClient::clientThread() noexcept {

stm->setNonBlock(true);
w_set_thread_name(
"client=",
unique_id,
":stm=",
uintptr_t(stm.get()),
":pid=",
stm->getPeerProcessID());
"client=", unique_id, ":stm=", uintptr_t(stm.get()), ":pid=", peerPid_);

client_is_owner = stm->peerIsOwner();

Expand Down Expand Up @@ -504,7 +497,7 @@ void UserClient::clientThread() noexcept {
":stm=",
uintptr_t(stm.get()),
":pid=",
stm->getPeerProcessID());
peerPid_);
}

} // namespace watchman
Expand Down
5 changes: 3 additions & 2 deletions watchman/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class Client : public std::enable_shared_from_this<Client> {
std::shared_ptr<Publisher::Subscriber> errorSub;

protected:
const pid_t peerPid_;
const facebook::eden::ProcessInfoHandle peerInfo_;

void sendErrorResponse(std::string_view formatted);

template <typename T, typename... Rest>
Expand Down Expand Up @@ -239,8 +242,6 @@ class UserClient final : public Client {
void clientThread() noexcept;

const std::chrono::system_clock::time_point since_;
const pid_t peerPid_;
const facebook::eden::ProcessInfoHandle peerInfo_;

ClientStatus status_;
};
Expand Down

0 comments on commit 463d38c

Please sign in to comment.