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:
Stiopa Koltsov 2021-04-02 11:35:09 -07:00 committed by Facebook GitHub Bot
parent cbadf861cb
commit afddf66676
3 changed files with 49 additions and 16 deletions

View 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

View 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

View File

@ -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 {