From 5f6d43269d6e781370e5d582c1b669060447966c Mon Sep 17 00:00:00 2001 From: Xinyi Wang Date: Wed, 27 Sep 2023 09:57:33 -0700 Subject: [PATCH] move the method to look up process to a common place Summary: As title in the task, I need to look up process info using this method. Move it to shared util class so that I can include them else where Reviewed By: kmancini Differential Revision: D49654377 fbshipit-source-id: d071926d023ef3a8cf2c92e1a328e4db11961bc5 --- CMakeLists.txt | 1 + watchman/Client.cpp | 13 ++----------- watchman/ProcessUtil.cpp | 27 +++++++++++++++++++++++++++ watchman/ProcessUtil.h | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 watchman/ProcessUtil.cpp create mode 100644 watchman/ProcessUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8252ba5f1b9d..169d847deade 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -605,6 +605,7 @@ watchman/PerfSample.cpp watchman/fs/ParallelWalk.cpp watchman/fs/Pipe.cpp watchman/ProcessLock.cpp +watchman/ProcessUtil.cpp # PubSub.cpp (in liblog) watchman/QueryableView.cpp watchman/SanityCheck.cpp diff --git a/watchman/Client.cpp b/watchman/Client.cpp index 1cc3d3721577..6c981b3905a1 100644 --- a/watchman/Client.cpp +++ b/watchman/Client.cpp @@ -9,11 +9,13 @@ #include +#include "eden/common/utils/ProcessInfoCache.h" #include "watchman/Command.h" #include "watchman/Errors.h" #include "watchman/Logging.h" #include "watchman/MapUtil.h" #include "watchman/Poison.h" +#include "watchman/ProcessUtil.h" #include "watchman/QueryableView.h" #include "watchman/Shutdown.h" #include "watchman/root/Root.h" @@ -23,17 +25,6 @@ namespace watchman { namespace { -using namespace facebook::eden; - -ProcessInfoCache& getProcessInfoCache() { - static auto* pic = new ProcessInfoCache; - return *pic; -} - -ProcessInfoHandle lookupProcessInfo(pid_t pid) { - return getProcessInfoCache().lookup(pid); -} - constexpr size_t kResponseLogLimit = 0; folly::Synchronized> clients; diff --git a/watchman/ProcessUtil.cpp b/watchman/ProcessUtil.cpp new file mode 100644 index 000000000000..867affcbf9bc --- /dev/null +++ b/watchman/ProcessUtil.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "watchman/ProcessUtil.h" + +#include "eden/common/utils/ProcessInfoCache.h" + +namespace watchman { + +using namespace facebook::eden; + +namespace { +ProcessInfoCache& getProcessInfoCache() { + static auto* pic = new ProcessInfoCache; + return *pic; +} +} // namespace + +ProcessInfoHandle lookupProcessInfo(pid_t pid) { + return getProcessInfoCache().lookup(pid); +} + +} // namespace watchman diff --git a/watchman/ProcessUtil.h b/watchman/ProcessUtil.h new file mode 100644 index 000000000000..c90a386979f0 --- /dev/null +++ b/watchman/ProcessUtil.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +namespace facebook::eden { +class ProcessInfoHandle; +} + +namespace watchman { + +using ProcessInfoHandle = facebook::eden::ProcessInfoHandle; + +ProcessInfoHandle lookupProcessInfo(pid_t pid); + +} // namespace watchman