Add port::GetProcessID() (#8693)

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
main
Peter Dillinger 3 years ago committed by Facebook GitHub Bot
parent 229350ef48
commit 318fe6941a
  1. 4
      db/internal_stats.cc
  2. 2
      port/port_posix.cc
  3. 2
      port/port_posix.h
  4. 2
      port/win/port_win.cc
  5. 2
      port/win/port_win.h

@ -23,6 +23,7 @@
#include "cache/cache_entry_stats.h" #include "cache/cache_entry_stats.h"
#include "db/column_family.h" #include "db/column_family.h"
#include "db/db_impl/db_impl.h" #include "db/db_impl/db_impl.h"
#include "port/port.h"
#include "rocksdb/system_clock.h" #include "rocksdb/system_clock.h"
#include "rocksdb/table.h" #include "rocksdb/table.h"
#include "table/block_based/cachable_entry.h" #include "table/block_based/cachable_entry.h"
@ -602,7 +603,8 @@ void InternalStats::CacheEntryRoleStats::BeginCollection(
++collection_count; ++collection_count;
role_map_ = CopyCacheDeleterRoleMap(); role_map_ = CopyCacheDeleterRoleMap();
std::ostringstream str; std::ostringstream str;
str << cache->Name() << "@" << static_cast<void*>(cache); str << cache->Name() << "@" << static_cast<void*>(cache) << "#"
<< port::GetProcessID();
cache_id = str.str(); cache_id = str.str();
cache_capacity = cache->GetCapacity(); cache_capacity = cache->GetCapacity();
} }

@ -263,6 +263,8 @@ void SetCpuPriority(ThreadId id, CpuPriority priority) {
#endif #endif
} }
int64_t GetProcessID() { return getpid(); }
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -219,5 +219,7 @@ using ThreadId = pid_t;
extern void SetCpuPriority(ThreadId id, CpuPriority priority); extern void SetCpuPriority(ThreadId id, CpuPriority priority);
int64_t GetProcessID();
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -277,6 +277,8 @@ void SetCpuPriority(ThreadId id, CpuPriority priority) {
(void)priority; (void)priority;
} }
int64_t GetProcessID() { return GetCurrentProcessId(); }
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -347,6 +347,8 @@ using ThreadId = int;
extern void SetCpuPriority(ThreadId id, CpuPriority priority); extern void SetCpuPriority(ThreadId id, CpuPriority priority);
int64_t GetProcessID();
} // namespace port } // namespace port

Loading…
Cancel
Save