瀏覽代碼

UI: Add basic profiler integration

Palana 10 年之前
父節點
當前提交
7c5d93b92a
共有 2 個文件被更改,包括 62 次插入4 次删除
  1. 54 3
      obs/obs-app.cpp
  2. 8 1
      obs/obs-app.hpp

+ 54 - 3
obs/obs-app.cpp

@@ -24,6 +24,7 @@
 #include <util/bmem.h>
 #include <util/dstr.h>
 #include <util/platform.h>
+#include <util/profiler.h>
 #include <obs-config.h>
 #include <obs.hpp>
 
@@ -456,8 +457,9 @@ bool OBSApp::InitTheme()
 	return SetTheme(t.str());
 }
 
-OBSApp::OBSApp(int &argc, char **argv)
-	: QApplication(argc, argv)
+OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
+	: QApplication(argc, argv),
+	  profilerNameStore(store)
 {}
 
 static void move_basic_to_profiles(void)
@@ -862,12 +864,61 @@ static void create_log_file(fstream &logFile)
 	}
 }
 
+static auto ProfilerNameStoreRelease = [](profiler_name_store_t *store)
+{
+	profiler_name_store_free(store);
+};
+
+using ProfilerNameStore =
+	std::unique_ptr<profiler_name_store_t,
+			decltype(ProfilerNameStoreRelease)>;
+
+ProfilerNameStore CreateNameStore()
+{
+	return ProfilerNameStore{profiler_name_store_create(),
+					ProfilerNameStoreRelease};
+}
+
+static auto SnapshotRelease = [](profiler_snapshot_t *snap)
+{
+	profile_snapshot_free(snap);
+};
+
+using ProfilerSnapshot = 
+	std::unique_ptr<profiler_snapshot_t, decltype(SnapshotRelease)>;
+
+ProfilerSnapshot GetSnapshot()
+{
+	return ProfilerSnapshot{profile_snapshot_create(), SnapshotRelease};
+}
+
+static auto ProfilerFree = [](void *)
+{
+	profiler_stop();
+
+	auto snap = GetSnapshot();
+
+	profiler_print(snap.get());
+	profiler_print_time_between_calls(snap.get());
+
+	profiler_free();
+};
+
 static int run_program(fstream &logFile, int argc, char *argv[])
 {
 	int ret = -1;
+
+	auto profilerNameStore = CreateNameStore();
+
+	std::unique_ptr<void, decltype(ProfilerFree)>
+		prof_release(static_cast<void*>(&ProfilerFree),
+				ProfilerFree);
+
+	profiler_start();
+
 	QCoreApplication::addLibraryPath(".");
 
-	OBSApp program(argc, argv);
+	OBSApp program(argc, argv, profilerNameStore.get());
 	try {
 		program.AppInit();
 

+ 8 - 1
obs/obs-app.hpp

@@ -22,6 +22,7 @@
 #include <QPointer>
 #include <obs.hpp>
 #include <util/lexer.h>
+#include <util/profiler.h>
 #include <util/util.hpp>
 #include <string>
 #include <memory>
@@ -62,6 +63,7 @@ private:
 	TextLookup                     textLookup;
 	OBSContext                     obsContext;
 	QPointer<OBSMainWindow>        mainWindow;
+	profiler_name_store_t          *profilerNameStore = nullptr;
 
 	bool InitGlobalConfig();
 	bool InitGlobalConfigDefaults();
@@ -69,7 +71,7 @@ private:
 	bool InitTheme();
 
 public:
-	OBSApp(int &argc, char **argv);
+	OBSApp(int &argc, char **argv, profiler_name_store_t *store);
 
 	void AppInit();
 	bool OBSInit();
@@ -93,6 +95,11 @@ public:
 		return textLookup.GetString(lookupVal);
 	}
 
+	profiler_name_store_t *GetProfilerNameStore() const
+	{
+		return profilerNameStore;
+	}
+
 	const char *GetLastLog() const;
 	const char *GetCurrentLog() const;