初始化提交
This commit is contained in:
		| @ -0,0 +1,79 @@ | ||||
| // Tencent is pleased to support the open source community by making sluaunreal available. | ||||
|  | ||||
| // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. | ||||
| // Licensed under the BSD 3-Clause License (the "License");  | ||||
| // you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||||
|  | ||||
| // https://opensource.org/licenses/BSD-3-Clause | ||||
|  | ||||
| // Unless required by applicable law or agreed to in writing,  | ||||
| // software distributed under the License is distributed on an "AS IS" BASIS,  | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | ||||
| // See the License for the specific language governing permissions and limitations under the License. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Containers/Ticker.h" | ||||
| #include "Modules/ModuleManager.h" | ||||
| #include "Framework/Commands/Commands.h" | ||||
| #include "slua_profile_inspector.h" | ||||
| #include "LuaMemoryProfile.h" | ||||
| #include "slua_profile.h" | ||||
|  | ||||
| /** Declares a log category for this module. */ | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogSluaProfile, Log, All); | ||||
|  | ||||
| namespace NS_SLUA | ||||
| { | ||||
|     class FProfileServer; | ||||
| } | ||||
|  | ||||
| class SLUA_PROFILE_API Fslua_profileModule : public IModuleInterface | ||||
| { | ||||
| public: | ||||
|  | ||||
|     /** IModuleInterface implementation */ | ||||
|     virtual void StartupModule() override; | ||||
|     virtual void ShutdownModule() override; | ||||
|  | ||||
|  | ||||
|     void PluginButtonClicked(); | ||||
| private: | ||||
|     // fields | ||||
|     FTickerDelegate TickDelegate; | ||||
| #if ENGINE_MAJOR_VERSION==5 | ||||
|     FTSTicker::FDelegateHandle TickDelegateHandle; | ||||
| #else | ||||
|     FDelegateHandle TickDelegateHandle; | ||||
| #endif | ||||
|  | ||||
|     TSharedPtr<SProfilerInspector> sluaProfilerInspector; | ||||
|     bool tabOpened = false; | ||||
|     TSharedPtr<class FUICommandList> PluginCommands; | ||||
|  | ||||
|     // functions | ||||
|     void OnTabClosed(TSharedRef<SDockTab> tab); | ||||
|  | ||||
|     TSharedRef<class SDockTab> OnSpawnPluginTab(const class FSpawnTabArgs& SpawnTabArgs); | ||||
|     bool Tick(float DeltaTime); | ||||
|     void ClearCurProfiler(); | ||||
|     void AddMenuExtension(FMenuBuilder& Builder); | ||||
|  | ||||
|     void debug_hook_c(NS_SLUA::FProfileMessagePtr Message); | ||||
| }; | ||||
|  | ||||
| #if WITH_EDITOR | ||||
| class Flua_profileCommands : public TCommands<Flua_profileCommands> | ||||
| { | ||||
| public: | ||||
|  | ||||
|     Flua_profileCommands(); | ||||
|  | ||||
|     // TCommands<> interface | ||||
|     virtual void RegisterCommands() override; | ||||
|  | ||||
| public: | ||||
|     TSharedPtr< FUICommandInfo > OpenPluginWindow; | ||||
| }; | ||||
| #endif | ||||
| @ -0,0 +1,216 @@ | ||||
| // Tencent is pleased to support the open source community by making sluaunreal available. | ||||
|  | ||||
| // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. | ||||
| // Licensed under the BSD 3-Clause License (the "License"); | ||||
| // you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||||
|  | ||||
| // https://opensource.org/licenses/BSD-3-Clause | ||||
|  | ||||
| // Unless required by applicable law or agreed to in writing, | ||||
| // software distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and limitations under the License. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "Widgets/Docking/SDockTab.h" | ||||
| #include "Widgets/Layout/SScrollBox.h" | ||||
| #include "Widgets/Layout/SWidgetSwitcher.h" | ||||
| #include "Widgets/Text/STextBlock.h" | ||||
| #include "Widgets/Views/STreeView.h" | ||||
| #include "Widgets/Views/SListView.h" | ||||
| #include "Widgets/Notifications/SProgressBar.h" | ||||
| #include "slua_remote_profile.h" | ||||
| #include "LuaMemoryProfile.h" | ||||
| #include "ProfileDataDefine.h" | ||||
| #include "slua_profile_inspector.h" | ||||
|  | ||||
| #define IsMemoryProfiler (m_stdLineVisibility.Get() != EVisibility::Visible) | ||||
| class SProfilerWidget; | ||||
| class SProfilerTabWidget; | ||||
| class Profiler; | ||||
| class SSlider; | ||||
|  | ||||
| class SLUA_PROFILE_API SProfilerInspector | ||||
| { | ||||
| public: | ||||
|     SProfilerInspector(); | ||||
|     ~SProfilerInspector(); | ||||
|      | ||||
|     void Refresh(TSharedPtr<FunctionProfileNode> funcInfoRoot, TMap<int64, NS_SLUA::LuaMemInfo>& memoryInfoList, MemoryFramePtr memoryFrame); | ||||
|     TSharedRef<class SDockTab> GetSDockTab(); | ||||
|     TSharedRef<ITableRow> OnGenerateMemRowForList(TSharedPtr<FileMemInfo> Item, const TSharedRef<STableViewBase>& OwnerTable); | ||||
|     void OnGetMemChildrenForTree(TSharedPtr<FileMemInfo> Parent, TArray<TSharedPtr<FileMemInfo>>& OutChildren); | ||||
|      | ||||
|     void OnGetChildrenForTree(TSharedPtr<FunctionProfileNode> Parent, TArray<TSharedPtr<FunctionProfileNode>>& OutChildren); | ||||
|     TSharedRef<ITableRow> OnGenerateRowForList(TSharedPtr<FunctionProfileNode> Item, const TSharedRef<STableViewBase>& OwnerTable); | ||||
|     void StartChartRolling(); | ||||
|     bool GetNeedProfilerCleared() const | ||||
|     { | ||||
|         return needProfilerCleared; | ||||
|     } | ||||
|     void SetNeedProfilerCleared(const bool needClear) | ||||
|     { | ||||
|         needProfilerCleared = needClear; | ||||
|     } | ||||
|  | ||||
|     MemFileInfoMap GetMemoryFrameInfo(int32 memoryFrameIndex) const; | ||||
|      | ||||
|     TSharedPtr<NS_SLUA::FProfileServer> ProfileServer; | ||||
|      | ||||
| private: | ||||
|     const static int sampleNum = cMaxSampleNum; | ||||
|     const static int fixRowWidth = 600; | ||||
|     const static int refreshInterval = 1; | ||||
|     const float perMilliSec = 1000.0f; | ||||
|     const static int maxMemoryFile = 30; | ||||
|     bool bIsTouching = false; | ||||
|     typedef TMap<FString, int> MemInfoIndexMap; | ||||
|      | ||||
|     TSharedPtr<STreeView<TSharedPtr<FunctionProfileNode>>> treeview; | ||||
|     TSharedPtr<SListView<TSharedPtr<FileMemInfo>>> listview; | ||||
|     TSharedPtr<STreeView<TSharedPtr<FileMemInfo>>> memTreeView; | ||||
|     TSharedPtr<SSlider> cpuSlider,memSlider; | ||||
|  | ||||
|     TSharedPtr<SProgressBar> profilerBarArray[sampleNum]; | ||||
|     TSharedPtr<SProfilerWidget> cpuProfilerWidget; | ||||
|     TSharedPtr<SProfilerWidget> memProfilerWidget; | ||||
|     TSharedPtr<SProfilerTabWidget> cpuTabWidget; | ||||
|     TSharedPtr<SProfilerTabWidget> memTabWidget; | ||||
|     TSharedPtr<SProfilerTabWidget> fpsTabWidget; | ||||
|     TSharedPtr<SWidgetSwitcher> tabSwitcher; | ||||
|      | ||||
|      | ||||
|     TArray<float> chartValArray; | ||||
|     TArray<float> memChartValArray; | ||||
|     bool stopChartRolling; | ||||
|     int cpuViewBeginIndex; | ||||
|     int memViewBeginIndex; | ||||
|      | ||||
|     float maxLuaMemory; | ||||
|     float avgLuaMemory; | ||||
|     double luaTotalMemSize; | ||||
|     double lastLuaTotalMemSize; | ||||
|     float maxProfileSamplesCostTime; | ||||
|     float avgProfileSamplesCostTime; | ||||
|     bool hasCleared; | ||||
|     bool needProfilerCleared; | ||||
|     FVector2D mouseUpPoint; | ||||
|     FVector2D mouseDownPoint; | ||||
|  | ||||
|      | ||||
|     TArray<TArray<TSharedPtr<FunctionProfileNode>>> allProfileData; | ||||
|  | ||||
|     TArray<TSharedPtr<FunctionProfileNode>> profileRootArr;     | ||||
|     TSharedPtr<FProflierMemNode> lastLuaMemNode; | ||||
|     /* holding all of the memory node which are showed on Profiler chart */ | ||||
|     MemNodeInfoList allLuaMemNodeList; | ||||
|      | ||||
|     /* refresh with the chart line, when mouse clicks down, it'll get point from this array */ | ||||
|     MemFileInfoMap shownFileInfo; | ||||
|     /* store the file name as the parent item in memory treeview */ | ||||
|     ShownMemInfoList shownParentFileName; | ||||
|      | ||||
|     void RefreshBarValue(); | ||||
|      | ||||
|     void ShowProfilerTree(TArray<TSharedPtr<FunctionProfileNode>>&selectedProfiler); | ||||
|     void CheckBoxChanged(ECheckBoxState newState); | ||||
|      | ||||
|     FString GenBrevFuncName(const FLuaFunctionDefine &functionDefine); | ||||
|      | ||||
|     void RestartMemoryStatistis(); | ||||
|     void OnClearBtnClicked(); | ||||
|     void CalcPointMemdiff(int beginIndex, int endIndex); | ||||
|     void CollectMemoryNode(TMap<int64, NS_SLUA::LuaMemInfo>& memoryInfoMap, MemoryFramePtr memoryFrame); | ||||
|     void CombineSameFileInfo(FProflierMemNode& proflierMemNode, int32 memoryFrameIndex); | ||||
|     int ContainsFile(FString& fileName, MemInfoIndexMap &list); | ||||
|     FString ChooseMemoryUnit(float memorySize); | ||||
|  | ||||
|     // save/load disk profile file | ||||
|     void OnLoadFileBtnClicked(); | ||||
|     void OnSaveFileBtnClicked(); | ||||
|     void OnCpuSliderValueChanged(float Value); | ||||
|     void OnMemSliderValueChanged(float Value); | ||||
|  | ||||
|     void ShowNotificationDialog(const FString& message); | ||||
|     TWeakPtr<class SNotificationItem> notification; | ||||
| }; | ||||
|  | ||||
| class SLUA_PROFILE_API SProfilerWidget : public SCompoundWidget | ||||
| { | ||||
| public: | ||||
|     SLATE_BEGIN_ARGS(SProfilerWidget) | ||||
|     :_StdLineVisibility(EVisibility::Visible) | ||||
|     {} | ||||
|      | ||||
|     SLATE_ATTRIBUTE(EVisibility, StdLineVisibility) | ||||
|      | ||||
|     SLATE_END_ARGS() | ||||
|      | ||||
|     /** Constructs this widget with InArgs */ | ||||
|     void Construct(const FArguments& InArgs); | ||||
|     void SetMouseMovePoint(FVector2D mouseDownPoint); | ||||
|     void SetMouseClickPoint(FVector2D mouseClickPoint); | ||||
|     void SetArrayValue(TArray<float> &chartValArray, float maxCostTime, float maxMemSize); | ||||
|     int CalcClickSampleIdx(FVector2D &cursorPos); | ||||
|     int CalcHoverSampleIdx(const FVector2D cursorPos); | ||||
|     void SetToolTipVal(float val); | ||||
|     void ClearClickedPoint(); | ||||
|     void SetStdLineVisibility(TAttribute<EVisibility> InVisibility); | ||||
|      | ||||
|     // SWidget interface | ||||
|     virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override; | ||||
|     virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; | ||||
| protected: | ||||
|     virtual FVector2D ComputeDesiredSize(float size) const override; | ||||
|      | ||||
| private: | ||||
|     void DrawStdLine(const FGeometry& AllottedGeometry, FSlateWindowElementList& OutDrawElements, int32 LayerId, float positionY, FString stdStr) const; | ||||
|     void AddStdLine(float &maxPointValue, float &stdLineValue, FString &stdLineName); | ||||
|     void CalcStdLine(float &maxCostTime); | ||||
|     void CalcMemStdText(float &maxMemorySize); | ||||
|      | ||||
|     TArray<FVector2D> m_arraylinePath; | ||||
|     TArray<float> m_arrayVal; | ||||
|  | ||||
|     TArray<float> m_stdPositionY; | ||||
|     TArray<FString> m_stdStr; | ||||
|     TArray<FString> m_stdMemStr; | ||||
|     TAttribute<EVisibility> m_stdLineVisibility; | ||||
|     const int32 m_cSliceCount = cMaxSampleNum; | ||||
|     const float m_cStdWidth = 1300; | ||||
|     float m_widgetWidth = 0; | ||||
|     const int32 m_cStdLeftPosition = 30; | ||||
|     float m_maxCostTime = 0; | ||||
|     float m_maxMemSize = 0; | ||||
|     float m_maxPointHeight = 0; | ||||
|     float m_pointInterval = 0; | ||||
|     float m_toolTipVal = 0; | ||||
|     int32 m_memStdScale = 1; | ||||
|     int32 m_pathArrayNum = 0; | ||||
|     FVector2D m_clickedPoint; | ||||
|     FVector2D m_mouseDownPoint; | ||||
|     const float m_cStdHighVal = cMaxViewHeight; | ||||
| }; | ||||
|  | ||||
| class SLUA_PROFILE_API SProfilerTabWidget : public SCompoundWidget | ||||
| { | ||||
|     SLATE_BEGIN_ARGS(SProfilerTabWidget) | ||||
|     : _TabName(FText::FromString("")) | ||||
|     , _TabIcon(FCoreStyle::Get().GetDefaultBrush()) | ||||
|     {} | ||||
|      | ||||
|     SLATE_ATTRIBUTE(FText, TabName) | ||||
|      | ||||
|     SLATE_ATTRIBUTE(const FSlateBrush*, TabIcon) | ||||
|      | ||||
|     SLATE_EVENT(FOnClicked, OnClicked) | ||||
|      | ||||
|     /** The visual style of the button */ | ||||
|     SLATE_END_ARGS() | ||||
|      | ||||
| public: | ||||
|     int32 activeTabIndex = 0; | ||||
|      | ||||
|     void Construct(const FArguments& InArgs); | ||||
| }; | ||||
| @ -0,0 +1,162 @@ | ||||
| // Tencent is pleased to support the open source community by making sluaunreal available. | ||||
|  | ||||
| // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. | ||||
| // Licensed under the BSD 3-Clause License (the "License");  | ||||
| // you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||||
|  | ||||
| // https://opensource.org/licenses/BSD-3-Clause | ||||
|  | ||||
| // Unless required by applicable law or agreed to in writing,  | ||||
| // software distributed under the License is distributed on an "AS IS" BASIS,  | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | ||||
| // See the License for the specific language governing permissions and limitations under the License. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "HAL/Runnable.h" | ||||
| #include "Containers/Queue.h" | ||||
| #include "Interfaces/IPv4/IPv4Endpoint.h" | ||||
| #include "LuaMemoryProfile.h" | ||||
| #include "Templates/SharedPointer.h" | ||||
| #include "Serialization/ArrayReader.h" | ||||
| #include "Delegates/DelegateCombinations.h" | ||||
|  | ||||
| class FSocket; | ||||
| class FTcpListener; | ||||
|  | ||||
| namespace NS_SLUA { | ||||
|     class FProfileConnection; | ||||
|     class FProfileMessage; | ||||
|      | ||||
|     typedef TSharedPtr<FProfileMessage, ESPMode::ThreadSafe> FProfileMessagePtr; | ||||
|     DECLARE_DELEGATE_OneParam(FOnProfileMessageDelegate, FProfileMessagePtr); | ||||
|  | ||||
|     class FProfileServer : public FRunnable | ||||
|     { | ||||
|     public: | ||||
|         FProfileServer(); | ||||
|         ~FProfileServer(); | ||||
|  | ||||
|         FOnProfileMessageDelegate& OnProfileMessageRecv(); | ||||
|  | ||||
|         TArray<TSharedPtr<FProfileConnection>> GetConnections(); | ||||
|  | ||||
|         static int32 Port; | ||||
|          | ||||
|     protected: | ||||
|         bool Init() override; | ||||
|         uint32 Run() override; | ||||
|         void Stop() override; | ||||
|          | ||||
|         void StopTransport(); | ||||
|  | ||||
|     private: | ||||
|         /** Callback for accepted connections to the local server. */ | ||||
|         bool HandleConnectionAccepted(FSocket* ClientSocket, const FIPv4Endpoint& ClientEndpoint); | ||||
|  | ||||
|         FRunnableThread* Thread; | ||||
|  | ||||
|         FIPv4Endpoint ListenEndpoint; | ||||
|  | ||||
|         FTcpListener* Listener; | ||||
|  | ||||
|         /** Current connections */ | ||||
|         TArray<TSharedPtr<FProfileConnection>> Connections; | ||||
|  | ||||
|         /** Holds a queue of pending connections. */ | ||||
|         TQueue<TSharedPtr<FProfileConnection>, EQueueMode::Mpsc> PendingConnections; | ||||
|          | ||||
|         FOnProfileMessageDelegate OnProfileMessageDelegate; | ||||
|  | ||||
|         bool bStop; | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|     * Implements a TCP message tunnel connection. | ||||
|     */ | ||||
|     class FProfileConnection | ||||
|         : public FRunnable | ||||
|         , public TSharedFromThis<FProfileConnection> | ||||
|     { | ||||
|     public: | ||||
|         FProfileConnection(FSocket* InSocket, const FIPv4Endpoint& InRemoteEndpoint); | ||||
|  | ||||
|         /** Virtual destructor. */ | ||||
|         virtual ~FProfileConnection(); | ||||
|  | ||||
|         void Start(); | ||||
|  | ||||
|     public: | ||||
|         enum EConnectionState | ||||
|         { | ||||
|             STATE_Connecting,                    // connecting but don't yet have RemoteNodeId | ||||
|             STATE_Connected,                    // connected and RemoteNodeId is valid | ||||
|             STATE_Disconnected                    // disconnected. Previous RemoteNodeId is retained | ||||
|         }; | ||||
|  | ||||
|         EConnectionState GetConnectionState() const; | ||||
|  | ||||
|         FSocket* GetSocket(); | ||||
|          | ||||
|         bool ReceiveData(TSharedPtr<FProfileMessage, ESPMode::ThreadSafe>& OutMessage); | ||||
|          | ||||
|         void Close(); | ||||
|  | ||||
|     private: | ||||
|         //~ FRunnable interface | ||||
|         virtual bool Init() override; | ||||
|         virtual uint32 Run() override; | ||||
|         virtual void Stop() override; | ||||
|         virtual void Exit() override; | ||||
|  | ||||
|     protected: | ||||
|         bool ReceiveMessages(); | ||||
|  | ||||
|         /** Holds the IP endpoint of the remote client. */ | ||||
|         FIPv4Endpoint RemoteEndpoint; | ||||
|  | ||||
|         /** Holds the connection socket. */ | ||||
|         FSocket* Socket; | ||||
|  | ||||
|         FRunnableThread* Thread; | ||||
|  | ||||
|         /** Holds the total number of bytes received from the connection. */ | ||||
|         uint64 TotalBytesReceived; | ||||
|  | ||||
|         /** Holds the collection of received Messages. */ | ||||
|         TQueue<TSharedPtr<FProfileMessage, ESPMode::ThreadSafe>, EQueueMode::Mpsc> Inbox; | ||||
|  | ||||
|         /** Message data we're currently in the process of receiving, if any */ | ||||
|         TSharedPtr<FArrayReader, ESPMode::ThreadSafe> RecvMessageData; | ||||
|  | ||||
|         int32 RecvMessageDataRemaining; | ||||
|          | ||||
|         int hookEvent; | ||||
|  | ||||
|         EConnectionState ConnectionState; | ||||
|  | ||||
|         bool bRun; | ||||
|     }; | ||||
|  | ||||
|     class FProfileMessage | ||||
|     { | ||||
|     public: | ||||
|         FProfileMessage(); | ||||
|         ~FProfileMessage(); | ||||
|  | ||||
|         bool Deserialize(const TSharedPtr<FArrayReader, ESPMode::ThreadSafe>& Message); | ||||
|  | ||||
|     public: | ||||
|         int Event; | ||||
|         int64 Time; | ||||
|  | ||||
|         int Linedefined; | ||||
|         FString Name; | ||||
|         FString ShortSrc; | ||||
|          | ||||
|         //Memory infomation | ||||
|         TArray<NS_SLUA::LuaMemInfo> memoryInfoList; | ||||
|         TArray<NS_SLUA::LuaMemInfo> memoryIncrease; | ||||
|     }; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user