Add even more profiler events
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "Engine/Utilities/Encryption.h"
|
||||
#include "Engine/Navigation/Navigation.h"
|
||||
#include "Engine/Particles/ParticleEmitter.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Input/Input.h"
|
||||
#include "Engine/Input/Mouse.h"
|
||||
#include "Engine/Input/Keyboard.h"
|
||||
@@ -1007,11 +1008,16 @@ public:
|
||||
|
||||
static void DeserializeSceneObject(SceneObject* sceneObject, MonoString* jsonObj)
|
||||
{
|
||||
PROFILE_CPU_NAMED("DeserializeSceneObject");
|
||||
|
||||
StringAnsi json;
|
||||
MUtils::ToString(jsonObj, json);
|
||||
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse(json.Get(), json.Length());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(json.Get(), json.Length());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
|
||||
@@ -1022,7 +1028,10 @@ public:
|
||||
modifier->EngineBuild = FLAXENGINE_VERSION_BUILD;
|
||||
Scripting::ObjectsLookupIdMapping.Set(&modifier.Value->IdsMapping);
|
||||
|
||||
sceneObject->Deserialize(document, modifier.Value);
|
||||
{
|
||||
PROFILE_CPU_NAMED("Deserialize");
|
||||
sceneObject->Deserialize(document, modifier.Value);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadAsset(Guid* id)
|
||||
|
||||
@@ -371,12 +371,14 @@ namespace FlaxEditor.Modules
|
||||
/// <param name="fullCleanup">True if cleanup all data (including serialized and cached data). Otherwise will just clear living references to the scene objects.</param>
|
||||
public void ClearRefsToSceneObjects(bool fullCleanup = false)
|
||||
{
|
||||
Profiler.BeginEvent("SceneModule.ClearRefsToSceneObjects");
|
||||
Editor.SceneEditing.Deselect();
|
||||
|
||||
if (fullCleanup)
|
||||
{
|
||||
Undo.Clear();
|
||||
}
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, Guid sceneId)
|
||||
|
||||
@@ -87,15 +87,18 @@ namespace FlaxEditor.States
|
||||
|
||||
private void CacheSelection()
|
||||
{
|
||||
Profiler.BeginEvent("PlayingState.CacheSelection");
|
||||
_selectedObjects.Clear();
|
||||
for (int i = 0; i < Editor.SceneEditing.Selection.Count; i++)
|
||||
{
|
||||
_selectedObjects.Add(Editor.SceneEditing.Selection[i].ID);
|
||||
}
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
private void RestoreSelection()
|
||||
{
|
||||
Profiler.BeginEvent("PlayingState.RestoreSelection");
|
||||
var count = Editor.SceneEditing.Selection.Count;
|
||||
Editor.SceneEditing.Selection.Clear();
|
||||
for (int i = 0; i < _selectedObjects.Count; i++)
|
||||
@@ -106,6 +109,7 @@ namespace FlaxEditor.States
|
||||
}
|
||||
if (Editor.SceneEditing.Selection.Count != count)
|
||||
Editor.SceneEditing.OnSelectionChanged();
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -114,6 +118,7 @@ namespace FlaxEditor.States
|
||||
/// <inheritdoc />
|
||||
public override void OnEnter()
|
||||
{
|
||||
Profiler.BeginEvent("PlayingState.OnEnter");
|
||||
Editor.OnPlayBeginning();
|
||||
|
||||
CacheSelection();
|
||||
@@ -137,6 +142,7 @@ namespace FlaxEditor.States
|
||||
RestoreSelection();
|
||||
|
||||
Editor.OnPlayBegin();
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
private void SetupEditorEnvOptions()
|
||||
@@ -156,6 +162,7 @@ namespace FlaxEditor.States
|
||||
/// <inheritdoc />
|
||||
public override void OnExit(State nextState)
|
||||
{
|
||||
Profiler.BeginEvent("PlayingState.OnExit");
|
||||
IsPaused = true;
|
||||
|
||||
// Remove references to the scene objects
|
||||
@@ -178,6 +185,7 @@ namespace FlaxEditor.States
|
||||
RestoreSelection();
|
||||
|
||||
Editor.OnPlayEnd();
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace FlaxEditor.Utilities
|
||||
{
|
||||
if (HasData)
|
||||
throw new InvalidOperationException("DuplicateScenes has already gathered scene data.");
|
||||
Profiler.BeginEvent("DuplicateScenes.GatherSceneData");
|
||||
|
||||
Editor.Log("Collecting scene data");
|
||||
|
||||
@@ -44,7 +45,10 @@ namespace FlaxEditor.Utilities
|
||||
var scenes = Level.Scenes;
|
||||
int scenesCount = scenes.Length;
|
||||
if (scenesCount == 0)
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new InvalidOperationException("Cannot gather scene data. No scene loaded.");
|
||||
}
|
||||
var sceneIds = new Guid[scenesCount];
|
||||
for (int i = 0; i < scenesCount; i++)
|
||||
{
|
||||
@@ -66,17 +70,24 @@ namespace FlaxEditor.Utilities
|
||||
|
||||
// Delete old scenes
|
||||
if (Level.UnloadAllScenes())
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new FlaxException("Failed to unload scenes.");
|
||||
}
|
||||
FlaxEngine.Scripting.FlushRemovedObjects();
|
||||
|
||||
// Ensure that old scenes has been unregistered
|
||||
{
|
||||
var noScenes = Level.Scenes;
|
||||
if (noScenes != null && noScenes.Length != 0)
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new FlaxException("Failed to unload scenes.");
|
||||
}
|
||||
}
|
||||
|
||||
Editor.Log(string.Format("Gathered {0} scene(s)!", scenesCount));
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,6 +97,7 @@ namespace FlaxEditor.Utilities
|
||||
{
|
||||
if (!HasData)
|
||||
throw new InvalidOperationException("DuplicateScenes has not gathered scene data yet.");
|
||||
Profiler.BeginEvent("DuplicateScenes.CreateScenes");
|
||||
|
||||
Editor.Log("Creating scenes");
|
||||
|
||||
@@ -96,8 +108,13 @@ namespace FlaxEditor.Utilities
|
||||
var data = _scenesData[i];
|
||||
var scene = Level.LoadSceneFromBytes(data.Bytes);
|
||||
if (scene == null)
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new FlaxException("Failed to deserialize scene");
|
||||
}
|
||||
}
|
||||
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,14 +122,19 @@ namespace FlaxEditor.Utilities
|
||||
/// </summary>
|
||||
public void DeletedScenes()
|
||||
{
|
||||
Profiler.BeginEvent("DuplicateScenes.DeletedScenes");
|
||||
Editor.Log("Restoring scene data");
|
||||
|
||||
// TODO: here we can keep changes for actors marked to keep their state after simulation
|
||||
|
||||
// Delete new scenes
|
||||
if (Level.UnloadAllScenes())
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new FlaxException("Failed to unload scenes.");
|
||||
}
|
||||
FlaxEngine.Scripting.FlushRemovedObjects();
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,6 +144,7 @@ namespace FlaxEditor.Utilities
|
||||
{
|
||||
if (!HasData)
|
||||
throw new InvalidOperationException("DuplicateScenes has not gathered scene data yet.");
|
||||
Profiler.BeginEvent("DuplicateScenes.RestoreSceneData");
|
||||
|
||||
// Deserialize old scenes
|
||||
for (int i = 0; i < _scenesData.Count; i++)
|
||||
@@ -129,7 +152,10 @@ namespace FlaxEditor.Utilities
|
||||
var data = _scenesData[i];
|
||||
var scene = Level.LoadSceneFromBytes(data.Bytes);
|
||||
if (scene == null)
|
||||
{
|
||||
Profiler.EndEvent();
|
||||
throw new FlaxException("Failed to deserialize scene");
|
||||
}
|
||||
|
||||
// Restore `dirty` state
|
||||
if (data.IsDirty)
|
||||
@@ -138,6 +164,7 @@ namespace FlaxEditor.Utilities
|
||||
_scenesData.Clear();
|
||||
|
||||
Editor.Log("Restored previous scenes");
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "Engine/Content/Factories/JsonAssetFactory.h"
|
||||
#include "Engine/Core/Cache.h"
|
||||
#include "Engine/Debug/Exceptions/JsonParseException.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Scripting/Scripting.h"
|
||||
#include "Engine/Utilities/StringConverter.h"
|
||||
|
||||
@@ -31,6 +32,7 @@ String JsonAssetBase::GetData() const
|
||||
{
|
||||
if (Data == nullptr)
|
||||
return String::Empty;
|
||||
PROFILE_CPU_NAMED("JsonAsset.GetData");
|
||||
|
||||
// Get serialized data
|
||||
rapidjson_flax::StringBuffer buffer;
|
||||
@@ -133,7 +135,10 @@ Asset::LoadResult JsonAssetBase::loadAsset()
|
||||
#endif
|
||||
|
||||
// Parse json document
|
||||
Document.Parse(data.Get<char>(), data.Length());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
Document.Parse(data.Get<char>(), data.Length());
|
||||
}
|
||||
if (Document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(Document.GetParseError(), Document.GetErrorOffset());
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Engine/Serialization/JsonWriters.h"
|
||||
#include "Engine/Level/Types.h"
|
||||
#include "Engine/Debug/Exceptions/JsonParseException.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include <ThirdParty/rapidjson/document.h>
|
||||
|
||||
bool JsonStorageProxy::IsValidExtension(const StringView& extension)
|
||||
@@ -17,6 +18,7 @@ bool JsonStorageProxy::IsValidExtension(const StringView& extension)
|
||||
|
||||
bool JsonStorageProxy::GetAssetInfo(const StringView& path, Guid& resultId, String& resultDataTypeName)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
// TODO: we could just open file and start reading until we find 'ID:..' without parsing whole file - could be much more faster
|
||||
|
||||
// Load file
|
||||
@@ -28,7 +30,10 @@ bool JsonStorageProxy::GetAssetInfo(const StringView& path, Guid& resultId, Stri
|
||||
|
||||
// Parse data
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse((const char*)fileData.Get(), fileData.Count());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse((const char*)fileData.Get(), fileData.Count());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), path);
|
||||
@@ -81,6 +86,7 @@ void ChangeIds(rapidjson_flax::Value& obj, rapidjson_flax::Document& document, c
|
||||
bool JsonStorageProxy::ChangeId(const StringView& path, const Guid& newId)
|
||||
{
|
||||
#if USE_EDITOR
|
||||
PROFILE_CPU();
|
||||
|
||||
// Load file
|
||||
Array<byte> fileData;
|
||||
@@ -91,7 +97,10 @@ bool JsonStorageProxy::ChangeId(const StringView& path, const Guid& newId)
|
||||
|
||||
// Parse data
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse((const char*)fileData.Get(), fileData.Count());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse((const char*)fileData.Get(), fileData.Count());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset(), path);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Engine/Content/AssetReference.h"
|
||||
#include "Engine/Engine/EngineService.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Streaming/StreamingSettings.h"
|
||||
|
||||
class GameSettingsService : public EngineService
|
||||
@@ -74,6 +75,7 @@ GameSettings* GameSettings::Get()
|
||||
{
|
||||
// Load root game settings asset.
|
||||
// It may be missing in editor during dev but must be ready in the build game.
|
||||
PROFILE_CPU();
|
||||
const auto assetPath = Globals::ProjectContentFolder / TEXT("GameSettings.json");
|
||||
GameSettingsAsset = Content::LoadAsync<JsonAsset>(assetPath);
|
||||
if (GameSettingsAsset == nullptr)
|
||||
@@ -99,6 +101,8 @@ GameSettings* GameSettings::Get()
|
||||
|
||||
bool GameSettings::Load()
|
||||
{
|
||||
PROFILE_CPU();
|
||||
|
||||
// Load main settings asset
|
||||
auto settings = Get();
|
||||
if (!settings)
|
||||
@@ -143,7 +147,7 @@ bool GameSettings::Load()
|
||||
|
||||
void GameSettings::Apply()
|
||||
{
|
||||
// TODO: impl this
|
||||
PROFILE_CPU();
|
||||
#define APPLY_SETTINGS(type) \
|
||||
{ \
|
||||
type* obj = type::Get(); \
|
||||
|
||||
@@ -1599,7 +1599,10 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
|
||||
|
||||
// Load JSON
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse(buffer, bufferSize);
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(buffer, bufferSize);
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
|
||||
@@ -1638,7 +1641,10 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
|
||||
|
||||
// Load JSON
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse(buffer, bufferSize);
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(buffer, bufferSize);
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
|
||||
@@ -1763,7 +1769,10 @@ void Actor::FromJson(const StringAnsiView& json)
|
||||
|
||||
// Load JSON
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse(json.Get(), json.Length());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(json.Get(), json.Length());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
|
||||
|
||||
@@ -496,6 +496,7 @@ public:
|
||||
// - load scenes (from temporary files)
|
||||
// Note: we don't want to override original scene files
|
||||
|
||||
PROFILE_CPU_NAMED("Level.ReloadScripts");
|
||||
LOG(Info, "Scripts reloading start");
|
||||
const auto startTime = DateTime::NowUTC();
|
||||
|
||||
@@ -565,7 +566,10 @@ public:
|
||||
// Parse json
|
||||
const auto& sceneData = scenes[i].Data;
|
||||
ISerializable::SerializeDocument document;
|
||||
document.Parse(sceneData.GetString(), sceneData.GetSize());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(sceneData.GetString(), sceneData.GetSize());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
LOG(Error, "Failed to deserialize scene {0}. Result: {1}", scenes[i].Name, GetParseError_En(document.GetParseError()));
|
||||
@@ -851,7 +855,10 @@ bool Level::loadScene(const BytesContainer& sceneData, bool autoInitialize, Scen
|
||||
|
||||
// Parse scene JSON file
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse(sceneData.Get<char>(), sceneData.Length());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse(sceneData.Get<char>(), sceneData.Length());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
Log::JsonParseException(document.GetParseError(), document.GetErrorOffset());
|
||||
@@ -869,9 +876,7 @@ bool Level::loadScene(rapidjson_flax::Document& document, bool autoInitialize, S
|
||||
LOG(Error, "Missing Data member.");
|
||||
return true;
|
||||
}
|
||||
|
||||
const int32 saveEngineBuild = JsonTools::GetInt(document, "EngineBuild", 0);
|
||||
|
||||
return loadScene(data->value, saveEngineBuild, autoInitialize, outScene);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,10 @@ void PrefabInstanceData::SerializePrefabInstances(Array<PrefabInstanceData>& pre
|
||||
writer.EndArray();
|
||||
|
||||
// Parse json to get DOM
|
||||
instance.Data.Parse(tmpBuffer.GetString(), tmpBuffer.GetSize());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
instance.Data.Parse(tmpBuffer.GetString(), tmpBuffer.GetSize());
|
||||
}
|
||||
if (instance.Data.HasParseError())
|
||||
{
|
||||
LOG(Warning, "Failed to parse serialized scene objects data.");
|
||||
@@ -462,7 +465,10 @@ bool PrefabInstanceData::SynchronizePrefabInstances(Array<PrefabInstanceData>& p
|
||||
writer.EndArray();
|
||||
|
||||
// Parse json to get DOM
|
||||
defaultInstanceData.Parse(tmpBuffer.GetString(), tmpBuffer.GetSize());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
defaultInstanceData.Parse(tmpBuffer.GetString(), tmpBuffer.GetSize());
|
||||
}
|
||||
if (defaultInstanceData.HasParseError())
|
||||
{
|
||||
LOG(Warning, "Failed to parse serialized scene objects data.");
|
||||
@@ -666,7 +672,10 @@ bool Prefab::ApplyAllInternal(Actor* targetActor, bool linkTargetActorObjectToPr
|
||||
newPrefabInstanceIdToDataIndex.EnsureCapacity(ObjectsCount * 4);
|
||||
{
|
||||
// Parse json to DOM document
|
||||
diffDataDocument.Parse(dataBuffer.GetString(), dataBuffer.GetSize());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
diffDataDocument.Parse(dataBuffer.GetString(), dataBuffer.GetSize());
|
||||
}
|
||||
if (diffDataDocument.HasParseError())
|
||||
{
|
||||
LOG(Warning, "Failed to parse serialized scene objects data.");
|
||||
|
||||
@@ -372,7 +372,10 @@ bool PrefabManager::CreatePrefab(Actor* targetActor, const StringView& outputPat
|
||||
{
|
||||
// Parse json to DOM document
|
||||
rapidjson_flax::Document doc;
|
||||
doc.Parse(actorsDataBuffer.GetString(), actorsDataBuffer.GetSize());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
doc.Parse(actorsDataBuffer.GetString(), actorsDataBuffer.GetSize());
|
||||
}
|
||||
if (doc.HasParseError())
|
||||
{
|
||||
LOG(Warning, "Failed to parse serialized actors data.");
|
||||
|
||||
@@ -85,18 +85,22 @@ namespace FlaxEngine
|
||||
#if FLAX_EDITOR
|
||||
internal static void InitializeGamePlugins()
|
||||
{
|
||||
Profiler.BeginEvent("PluginManager.InitializeGamePlugins");
|
||||
for (var i = 0; i < _gamePlugins.Count; i++)
|
||||
{
|
||||
InvokeInitialize(_gamePlugins[i]);
|
||||
}
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
|
||||
internal static void DeinitializeGamePlugins()
|
||||
{
|
||||
Profiler.BeginEvent("PluginManager.DeinitializeGamePlugins");
|
||||
for (var i = _gamePlugins.Count - 1; i >= 0; i--)
|
||||
{
|
||||
InvokeDeinitialize(_gamePlugins[i]);
|
||||
}
|
||||
Profiler.EndEvent();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -259,7 +259,10 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde
|
||||
|
||||
// Parse Json data
|
||||
rapidjson_flax::Document document;
|
||||
document.Parse((char*)fileData.Get(), fileData.Count());
|
||||
{
|
||||
PROFILE_CPU_NAMED("Json.Parse");
|
||||
document.Parse((char*)fileData.Get(), fileData.Count());
|
||||
}
|
||||
if (document.HasParseError())
|
||||
{
|
||||
LOG(Error, "Failed to file contents.");
|
||||
|
||||
Reference in New Issue
Block a user