2020-01-15 04:36:44 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Trace/StoreService.h"
|
|
|
|
|
#include "Asio/Asio.h"
|
|
|
|
|
#include "AsioContext.h"
|
|
|
|
|
#include "AsioRecorder.h"
|
|
|
|
|
#include "AsioStore.h"
|
|
|
|
|
#include "AsioStoreCborServer.h"
|
2020-01-15 07:02:43 -05:00
|
|
|
#include "HAL/PlatformFile.h"
|
2020-01-15 04:36:44 -05:00
|
|
|
|
2020-11-17 06:54:28 -04:00
|
|
|
namespace UE {
|
|
|
|
|
namespace Trace {
|
2020-01-15 04:36:44 -05:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2020-01-22 05:03:00 -05:00
|
|
|
struct FStoreServiceImpl
|
2020-01-15 04:36:44 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2020-01-22 05:03:00 -05:00
|
|
|
FStoreServiceImpl(const FStoreService::FDesc& Desc);
|
2020-01-22 05:06:31 -05:00
|
|
|
~FStoreServiceImpl();
|
2020-01-15 04:36:44 -05:00
|
|
|
FAsioContext Context;
|
|
|
|
|
FAsioStore Store;
|
|
|
|
|
FAsioRecorder Recorder;
|
|
|
|
|
FAsioStoreCborServer CborServer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2020-01-22 05:03:00 -05:00
|
|
|
FStoreServiceImpl::FStoreServiceImpl(const FStoreService::FDesc& Desc)
|
2020-01-15 04:36:44 -05:00
|
|
|
: Context(Desc.ThreadCount)
|
|
|
|
|
, Store(Context.Get(), Desc.StoreDir)
|
|
|
|
|
, Recorder(Context.Get(), Store)
|
|
|
|
|
, CborServer(Context.Get(), Store, Recorder)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 05:06:31 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
FStoreServiceImpl::~FStoreServiceImpl()
|
|
|
|
|
{
|
2020-02-05 14:26:36 -05:00
|
|
|
asio::post(Context.Get(), [this] () {
|
2020-01-28 07:41:32 -05:00
|
|
|
CborServer.Close();
|
|
|
|
|
Recorder.Close();
|
|
|
|
|
Store.Close();
|
|
|
|
|
});
|
2020-01-28 04:11:19 -05:00
|
|
|
Context.Wait();
|
2020-01-22 05:06:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-15 04:36:44 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
FStoreService* FStoreService::Create(const FDesc& InDesc)
|
|
|
|
|
{
|
|
|
|
|
FDesc Desc = InDesc;
|
|
|
|
|
|
|
|
|
|
IPlatformFile& PlatformFile = IPlatformFile::GetPlatformPhysical();
|
|
|
|
|
PlatformFile.CreateDirectory(Desc.StoreDir);
|
|
|
|
|
|
|
|
|
|
if (Desc.ThreadCount <= 0)
|
|
|
|
|
{
|
|
|
|
|
Desc.ThreadCount = FPlatformMisc::NumberOfCoresIncludingHyperthreads();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 07:56:36 -05:00
|
|
|
// TODO: not thread safe yet
|
|
|
|
|
Desc.ThreadCount = 1;
|
|
|
|
|
|
2020-01-22 05:03:00 -05:00
|
|
|
FStoreServiceImpl* Impl = new FStoreServiceImpl(Desc);
|
2020-01-15 04:36:44 -05:00
|
|
|
if (Desc.RecorderPort >= 0)
|
|
|
|
|
{
|
|
|
|
|
FAsioRecorder& Recorder = Impl->Recorder;
|
|
|
|
|
Recorder.StartServer(Desc.RecorderPort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Impl->Context.Start();
|
|
|
|
|
|
2020-01-22 05:03:00 -05:00
|
|
|
return (FStoreService*)Impl;
|
2020-01-15 04:36:44 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-22 05:03:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
void FStoreService::operator delete (void* Addr)
|
|
|
|
|
{
|
|
|
|
|
auto* Self = (FStoreServiceImpl*)Addr;
|
|
|
|
|
delete Self;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 04:36:44 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
uint32 FStoreService::GetPort() const
|
|
|
|
|
{
|
2020-01-22 05:03:00 -05:00
|
|
|
auto* Self = (FStoreServiceImpl*)this;
|
|
|
|
|
return Self->CborServer.GetPort();
|
2020-01-15 04:36:44 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-23 08:53:24 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
uint32 FStoreService::GetRecorderPort() const
|
|
|
|
|
{
|
|
|
|
|
auto* Self = (FStoreServiceImpl*)this;
|
|
|
|
|
return Self->Recorder.GetPort();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 04:36:44 -05:00
|
|
|
} // namespace Trace
|
2020-11-17 06:54:28 -04:00
|
|
|
} // namespace UE
|