]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Add port::GetProcessID() (#8693)
authorPeter Dillinger <peterd@fb.com>
Wed, 25 Aug 2021 00:45:01 +0000 (17:45 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 25 Aug 2021 00:46:14 +0000 (17:46 -0700)
Summary:
Useful in some places for object uniqueness across processes.
Currently used for generating a host-wide identifier of Cache objects
but expected to be used soon in some unique id generation code.

`int64_t` is chosen for return type because POSIX uses signed integer type,
usually `int`, for `pid_t` and Windows uses `DWORD`, which is `uint32_t`.

Future work: avoid copy-pasted declarations in port_*.h, perhaps with
port_common.h always included from port.h

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8693

Test Plan: manual for now

Reviewed By: ajkr, anand1976

Differential Revision: D30492876

Pulled By: pdillinger

fbshipit-source-id: 39fc2788623cc9f4787866bdb67a4d183dde7eef

db/internal_stats.cc
port/port_posix.cc
port/port_posix.h
port/win/port_win.cc
port/win/port_win.h

index a91883975dd3d7dbdff5ce01716b5eca3ceee07f..abe4b660744db12f7f32d42c24553fb10768fa6e 100644 (file)
@@ -23,6 +23,7 @@
 #include "cache/cache_entry_stats.h"
 #include "db/column_family.h"
 #include "db/db_impl/db_impl.h"
+#include "port/port.h"
 #include "rocksdb/system_clock.h"
 #include "rocksdb/table.h"
 #include "table/block_based/cachable_entry.h"
@@ -602,7 +603,8 @@ void InternalStats::CacheEntryRoleStats::BeginCollection(
   ++collection_count;
   role_map_ = CopyCacheDeleterRoleMap();
   std::ostringstream str;
-  str << cache->Name() << "@" << static_cast<void*>(cache);
+  str << cache->Name() << "@" << static_cast<void*>(cache) << "#"
+      << port::GetProcessID();
   cache_id = str.str();
   cache_capacity = cache->GetCapacity();
 }
index 112984de2963c89376c0a9891aede8af526e2414..57f19e33d8aedd3e97c52dd8d1a1c9b5cc288392 100644 (file)
@@ -263,6 +263,8 @@ void SetCpuPriority(ThreadId id, CpuPriority priority) {
 #endif
 }
 
+int64_t GetProcessID() { return getpid(); }
+
 }  // namespace port
 }  // namespace ROCKSDB_NAMESPACE
 
index 90f131e13104bb0d7f50cb1b7f119aa9d64f654e..fa23f9c336e7ea71049e37058834d5d7345520b5 100644 (file)
@@ -219,5 +219,7 @@ using ThreadId = pid_t;
 
 extern void SetCpuPriority(ThreadId id, CpuPriority priority);
 
+int64_t GetProcessID();
+
 } // namespace port
 }  // namespace ROCKSDB_NAMESPACE
index bd7b55f42789ea8bd9ec05dc3bdba8460b2f8901..b28a44895517b51d38b2a6b2fbe448a079856f33 100644 (file)
@@ -277,6 +277,8 @@ void SetCpuPriority(ThreadId id, CpuPriority priority) {
   (void)priority;
 }
 
+int64_t GetProcessID() { return GetCurrentProcessId(); }
+
 }  // namespace port
 }  // namespace ROCKSDB_NAMESPACE
 
index a6a6de2780194527f909341665c05debefea1b38..7de9b61c519a7c8ed2c8cb53891b8f9d9bc51076 100644 (file)
@@ -347,6 +347,8 @@ using ThreadId = int;
 
 extern void SetCpuPriority(ThreadId id, CpuPriority priority);
 
+int64_t GetProcessID();
+
 }  // namespace port