[Bf-blender-cvs] [7f15534e4c1] profiler-editor: add profile listener
Jacques Lucke
noreply at git.blender.org
Thu Apr 29 11:30:46 CEST 2021
Commit: 7f15534e4c13d75217dc1cc58d91501a2303a1c0
Author: Jacques Lucke
Date: Mon Apr 26 17:35:37 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rB7f15534e4c13d75217dc1cc58d91501a2303a1c0
add profile listener
===================================================================
M source/blender/blenlib/BLI_profile_manage.hh
M source/blender/blenlib/CMakeLists.txt
A source/blender/blenlib/intern/profile.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_profile_manage.hh b/source/blender/blenlib/BLI_profile_manage.hh
index da17598c201..650009850af 100644
--- a/source/blender/blenlib/BLI_profile_manage.hh
+++ b/source/blender/blenlib/BLI_profile_manage.hh
@@ -46,4 +46,14 @@ struct RecordedProfile {
Vector<ProfileTaskEnd> task_ends;
};
+class ProfileListener {
+ public:
+ ProfileListener();
+ virtual ~ProfileListener();
+
+ virtual void handle(const RecordedProfile &profile) = 0;
+
+ static void flush_to_all();
+};
+
} // namespace blender::profile
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index e66049c9bd6..95789c1fa00 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -112,6 +112,7 @@ set(SRC
intern/path_util.c
intern/polyfill_2d.c
intern/polyfill_2d_beautify.c
+ intern/profile.cc
intern/quadric.c
intern/rand.cc
intern/rct.c
@@ -254,6 +255,9 @@ set(SRC
BLI_polyfill_2d.h
BLI_polyfill_2d_beautify.h
BLI_probing_strategies.hh
+ BLI_profile.h
+ BLI_profile.hh
+ BLI_profile_manage.hh
BLI_quadric.h
BLI_rand.h
BLI_rand.hh
diff --git a/source/blender/blenlib/intern/profile.cc b/source/blender/blenlib/intern/profile.cc
new file mode 100644
index 00000000000..f248f05344b
--- /dev/null
+++ b/source/blender/blenlib/intern/profile.cc
@@ -0,0 +1,84 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <mutex>
+
+#include "BLI_profile.hh"
+#include "BLI_profile_manage.hh"
+
+namespace blender::profile {
+
+static void start_profiling()
+{
+ bli_profiling_is_enabled = true;
+}
+
+static void stop_profiling()
+{
+ bli_profiling_is_enabled = false;
+}
+
+static std::mutex listeners_mutex;
+static RawVector<ProfileListener *> listeners;
+
+ProfileListener::ProfileListener()
+{
+ std::lock_guard lock{listeners_mutex};
+ listeners.append(this);
+ if (listeners.size() == 1) {
+ start_profiling();
+ }
+}
+
+ProfileListener::~ProfileListener()
+{
+ std::lock_guard lock{listeners_mutex};
+ listeners.remove_first_occurrence_and_reorder(this);
+ if (listeners.is_empty()) {
+ stop_profiling();
+ }
+}
+
+void ProfileListener::flush_to_all()
+{
+ std::lock_guard lock{listeners_mutex};
+ RecordedProfile recorded_profile;
+
+ for (ProfileListener *listener : listeners) {
+ listener->handle(recorded_profile);
+ }
+}
+
+} // namespace blender::profile
+
+using namespace blender::profile;
+
+void _bli_profile_task_begin(BLI_ProfileTask *task, const char *name)
+{
+ UNUSED_VARS(task, name);
+}
+
+void _bli_profile_task_begin_subtask(BLI_ProfileTask *task,
+ const char *name,
+ const BLI_ProfileTask *parent_task)
+{
+ UNUSED_VARS(task, name, parent_task);
+}
+
+void _bli_profile_task_end(BLI_ProfileTask *task)
+{
+ UNUSED_VARS(task);
+}
More information about the Bf-blender-cvs
mailing list