Skip to content

Commit

Permalink
move client info into base for all samples
Browse files Browse the repository at this point in the history
Summary:
I added client logging to the Watchman `dispatch_command` event.

Watchman has a few different types of scuba events:
- query_execute
- sync_to_now
- full_crawl
- clock_test
- saved_state
- dropped
- age_out

Some of these events are associated with a specific client request, so I would
like to include client information there as well. There are a few that are not
related to a specific client event:
- full_crawl
- clock_test
- dropped
- age_out

So I only intend to add client information to
- query_execute
- sync_to_now
- saved_state

Going to move these client attributes to the more generically used
MetadataEventData instead of being on the event types for each event to avoid
copy paste.

Reviewed By: genevievehelsel

Differential Revision: D61684457

fbshipit-source-id: bf4765780cfd09c7ff5a0a3f0ef56dcc10f58dfd
  • Loading branch information
Katie Mancini authored and facebook-github-bot committed Aug 27, 2024
1 parent 85ea01a commit c2afc74
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eden/common/utils/ProcessInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "eden/common/utils/ProcessInfoCache.h"

#include <folly/MapUtil.h>
#include <folly/String.h>
#include <folly/container/EvictingCacheMap.h>
#include <folly/futures/SharedPromise.h>
#include <folly/logging/xlog.h>
Expand Down Expand Up @@ -418,4 +419,10 @@ std::optional<ProcessName> ProcessInfoCache::getProcessName(pid_t pid) {
readProcessSimpleName(pid)};
}

/*static*/ std::string ProcessInfoCache::cleanProcessCommandline(
std::string processName) {
std::replace(processName.begin(), processName.end(), '\0', ' ');
return folly::rtrimWhitespace(processName).str();
}

} // namespace facebook::eden
8 changes: 8 additions & 0 deletions eden/common/utils/ProcessInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ class ProcessInfoCache {
*/
std::optional<ProcessName> getProcessName(pid_t pid);

/**
* Commandlines (on linux anyways) use \0 instead of spaces to separate
* arguments. sl is often a command we are interested in. and sl also
* doed some funky commandline manipulation that causes a bunch of \0 to be
* on the end of their commandline. This will clean those off.
*/
static std::string cleanProcessCommandline(std::string process);

private:
struct State {
std::unordered_map<pid_t, std::shared_ptr<detail::ProcessInfoNode>> infos;
Expand Down
33 changes: 33 additions & 0 deletions eden/common/utils/test/ProcessInfoCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,37 @@ TEST(ProcessInfoCache, multipleLookups) {
thread1.join();
thread2.join();
}

TEST(ProcessInfoCache, testSlCommandlineCleaning) {
// Sapling does some commandline manipulation to name the background processes
// something like pfc[worker/XXXXXXXX]. But this causes the commanline to be
// full of null bytes. This is something we want to be filtered out in
// telemetry.

// note to editor: we use the char *, size_t variant of the string constructor
// o.w the \0 will be interpreted as the end of the string!
auto sl_worker_raw_cmdline = std::string{
"pfc[worker/663504]\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
112};

EXPECT_EQ(
"pfc[worker/663504]",
ProcessInfoCache::cleanProcessCommandline(sl_worker_raw_cmdline));
}

TEST(ProcessInfoCache, testBuckCommandlineCleaning) {
// Commandlines are \0 byte separated. We should turn those null bytes into
// spaces to make the commandlines easier to read in telemetry.

// note to editor: we use the char *, size_t variant of the string constructor
// o.w the \0 will be interpreted as the end of the string!
auto buck2_raw_cmdline = std::string{
"buck2d[fbsource]\u0000--isolation-dir\u0000v2\u0000daemon\u0000{\"buck_config\":\"somevalue\"}\u0000",
70};

EXPECT_EQ(
"buck2d[fbsource] --isolation-dir v2 daemon {\"buck_config\":\"somevalue\"}",
ProcessInfoCache::cleanProcessCommandline(buck2_raw_cmdline));
}

} // namespace facebook::eden

0 comments on commit c2afc74

Please sign in to comment.