diff --git a/LibCarla/source/carla/rpc/Server.h b/LibCarla/source/carla/rpc/Server.h index 6b51e7c7c..8f647eccc 100644 --- a/LibCarla/source/carla/rpc/Server.h +++ b/LibCarla/source/carla/rpc/Server.h @@ -51,6 +51,7 @@ namespace rpc { } void SyncRunFor(time_duration duration) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); _sync_io_context.reset(); _sync_io_context.run_for(duration.to_chrono()); } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp index 96a5285ec..1b393421c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp @@ -111,6 +111,7 @@ void FCarlaEngine::NotifyEndEpisode() void FCarlaEngine::OnPreTick(UWorld *, ELevelTick TickType, float DeltaSeconds) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); if (TickType == ELevelTick::LEVELTICK_All) { // update frame counter @@ -132,6 +133,7 @@ void FCarlaEngine::OnPreTick(UWorld *, ELevelTick TickType, float DeltaSeconds) void FCarlaEngine::OnPostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); // tick the recorder/replayer system if (GetCurrentEpisode()) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp index 742d2e899..405e9462d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp @@ -46,6 +46,7 @@ static void WritePixelsToBuffer_Vulkan( uint32 Offset, FRHICommandListImmediate &InRHICmdList) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); check(IsInRenderingThread()); auto RenderResource = static_cast(RenderTarget.Resource); @@ -58,12 +59,18 @@ static void WritePixelsToBuffer_Vulkan( FIntPoint Rect = RenderResource->GetSizeXY(); // NS: Extra copy here, don't know how to avoid it. - InRHICmdList.ReadSurfaceData( - Texture, - FIntRect(0, 0, Rect.X, Rect.Y), - gPixels, - FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)); - Buffer.copy_from(Offset, gPixels); + { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT("Read Surface"); + InRHICmdList.ReadSurfaceData( + Texture, + FIntRect(0, 0, Rect.X, Rect.Y), + gPixels, + FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)); + } + { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT("Buffer Copy"); + Buffer.copy_from(Offset, gPixels); + } } // ============================================================================= @@ -130,6 +137,7 @@ void FPixelReader::WritePixelsToBuffer( FRHICommandListImmediate &InRHICmdList ) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); check(IsInRenderingThread()); if (IsVulkanPlatform(GMaxRHIShaderPlatform) || IsD3DPlatform(GMaxRHIShaderPlatform, false)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h index 00d8cf743..17d57d351 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h @@ -101,6 +101,8 @@ void FPixelReader::SendPixelsInRenderThread(TSensor &Sensor) ( [&Sensor, Stream=Sensor.GetDataStream(Sensor)](auto &InRHICmdList) mutable { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT("FWritePixels_SendPixelsInRenderThread"); + /// @todo Can we make sure the sensor is not going to be destroyed? if (!Sensor.IsPendingKill()) { @@ -113,12 +115,16 @@ void FPixelReader::SendPixelsInRenderThread(TSensor &Sensor) if(Buffer.data()) { SCOPE_CYCLE_COUNTER(STAT_CarlaSensorStreamSend); + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT("Stream Send"); Stream.Send(Sensor, std::move(Buffer)); } } } ); - // Blocks until the render thread has finished all it's tasks - Sensor.WaitForRenderThreadToFinsih(); + { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT("FPixelReader::WaitForRenderThreadToFinsih"); + // Blocks until the render thread has finished all it's tasks + Sensor.WaitForRenderThreadToFinsih(); + } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp index 2225f796e..5f8f0f177 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/WorldObserver.cpp @@ -179,7 +179,7 @@ static carla::Buffer FWorldObserver_Serialize( bool MapChange, bool PendingLightUpdates) { - + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); using Serializer = carla::sensor::s11n::EpisodeStateSerializer; using SimulationState = carla::sensor::s11n::EpisodeStateSerializer::SimulationState; using ActorDynamicState = carla::sensor::data::ActorDynamicState; @@ -243,6 +243,7 @@ void FWorldObserver::BroadcastTick( bool MapChange, bool PendingLightUpdates) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); auto AsyncStream = Stream.MakeAsyncDataStream(*this, Episode.GetElapsedGameTime()); auto buffer = FWorldObserver_Serialize( diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index a2f963b6e..597d24a46 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -1664,14 +1664,31 @@ void FCarlaServer::AsyncRun(uint32 NumberOfWorkerThreads) { check(Pimpl != nullptr); /// @todo Define better the number of threads each server gets. - auto RPCThreads = NumberOfWorkerThreads / 2u; - auto StreamingThreads = NumberOfWorkerThreads - RPCThreads; - Pimpl->Server.AsyncRun(std::max(2u, RPCThreads)); - Pimpl->StreamingServer.AsyncRun(std::max(2u, StreamingThreads)); + int32_t RPCThreads = std::max(2u, NumberOfWorkerThreads / 2u); + int32_t StreamingThreads = std::max(2u, NumberOfWorkerThreads - RPCThreads); + + UE_LOG(LogCarla, Error, TEXT("FCommandLine %s"), FCommandLine::Get()); + + if(!FParse::Value(FCommandLine::Get(), TEXT("-RPCThreads="), RPCThreads)) + { + RPCThreads = std::max(2u, NumberOfWorkerThreads / 2u); + } + if(!FParse::Value(FCommandLine::Get(), TEXT("-StreamingThreads="), StreamingThreads)) + { + StreamingThreads = std::max(2u, NumberOfWorkerThreads - RPCThreads); + } + + UE_LOG(LogCarla, Error, TEXT("FCarlaServer AsyncRun %d, RPCThreads %d, StreamingThreads %d"), + NumberOfWorkerThreads, RPCThreads, StreamingThreads); + + Pimpl->Server.AsyncRun(RPCThreads); + Pimpl->StreamingServer.AsyncRun(StreamingThreads); + } void FCarlaServer::RunSome(uint32 Milliseconds) { + TRACE_CPUPROFILER_EVENT_SCOPE_TEXT(__FUNCTION__); Pimpl->Server.SyncRunFor(carla::time_duration::milliseconds(Milliseconds)); }