mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
Move getSessionId to a separate file
Summary: Refactoring to make the following diff smaller. Reviewed By: chadaustin Differential Revision: D27522581 fbshipit-source-id: 8f858714fcbfe4b8f8b1c3678bb2003623abbd94
This commit is contained in:
parent
cbadf861cb
commit
afddf66676
28
eden/fs/telemetry/SessionId.cpp
Normal file
28
eden/fs/telemetry/SessionId.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This software may be used and distributed according to the terms of the
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include "eden/fs/telemetry/SessionId.h"
|
||||
#include <random>
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t generateSessionId() {
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> u;
|
||||
return u(rd);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace facebook::eden {
|
||||
|
||||
uint32_t getSessionId() {
|
||||
static auto sessionId = generateSessionId();
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
} // namespace facebook::eden
|
20
eden/fs/telemetry/SessionId.h
Normal file
20
eden/fs/telemetry/SessionId.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This software may be used and distributed according to the terms of the
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace facebook::eden {
|
||||
|
||||
/**
|
||||
* Returns a random, process-stable positive integer in the range of [0,
|
||||
* UINT32_MAX]
|
||||
*/
|
||||
uint32_t getSessionId();
|
||||
|
||||
} // namespace facebook::eden
|
@ -6,30 +6,15 @@
|
||||
*/
|
||||
|
||||
#include "eden/fs/telemetry/StructuredLogger.h"
|
||||
#include "eden/fs/telemetry/SessionId.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <random>
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* The log database populates the time field automatically.
|
||||
*/
|
||||
constexpr bool kExplicitTimeField = true;
|
||||
|
||||
uint32_t generateSessionId() {
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> u;
|
||||
return u(rd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random, process-stable positive integer in the range of [0,
|
||||
* UINT32_MAX]
|
||||
*/
|
||||
uint32_t getSessionId() {
|
||||
static auto sessionId = generateSessionId();
|
||||
return sessionId;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace facebook {
|
||||
|
Loading…
Reference in New Issue
Block a user