[Bf-blender-cvs] [e36beb7f9e9] profiler-editor: start adding profile blenlib code
Jacques Lucke
noreply at git.blender.org
Thu Apr 29 11:30:46 CEST 2021
Commit: e36beb7f9e973f98dfbb804ac092f885ee25516a
Author: Jacques Lucke
Date: Mon Apr 26 17:14:18 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rBe36beb7f9e973f98dfbb804ac092f885ee25516a
start adding profile blenlib code
===================================================================
A source/blender/blenlib/BLI_profile.h
A source/blender/blenlib/BLI_profile.hh
A source/blender/blenlib/BLI_profile_manage.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_profile.h b/source/blender/blenlib/BLI_profile.h
new file mode 100644
index 00000000000..0631098aad0
--- /dev/null
+++ b/source/blender/blenlib/BLI_profile.h
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bool bli_profiling_is_enabled;
+
+typedef struct BLI_ProfileTask {
+ uint64_t id;
+} BLI_ProfileTask;
+
+void _bli_profile_task_begin(BLI_ProfileTask *task, const char *name);
+void _bli_profile_task_begin_subtask(BLI_ProfileTask *task,
+ const char *name,
+ const BLI_ProfileTask *parent_task);
+void _bli_profile_task_end(BLI_ProfileTask *task);
+
+#define BLI_profile_task_begin(task_ptr, name) \
+ if (bli_profiling_is_enabled) { \
+ _bli_profile_task_begin((task_ptr), (name)); \
+ } \
+ ((void)0)
+
+#define BLI_profile_task_begin_subtask(task_ptr, name, parent_task) \
+ if (bli_profiling_is_enabled) { \
+ _bli_profile_task_begin_subtask((task_ptr), (name), (parent_task)); \
+ } \
+ ((void)0)
+
+#define BLI_profile_task_end(task_ptr) \
+ if (bli_profiling_is_enabled) { \
+ _bli_profile_task_end(task_ptr); \
+ } \
+ ((void)0)
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenlib/BLI_profile.hh b/source/blender/blenlib/BLI_profile.hh
new file mode 100644
index 00000000000..2e52c8f1447
--- /dev/null
+++ b/source/blender/blenlib/BLI_profile.hh
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "BLI_profile.h"
+
+namespace blender::profile {
+
+class ProfileTask {
+ private:
+ BLI_ProfileTask task_;
+
+ public:
+ ProfileTask(const char *name)
+ {
+ BLI_profile_task_begin(&task_, name);
+ }
+
+ ProfileTask(const char *name, const BLI_ProfileTask *parent_task)
+ {
+ BLI_profile_task_begin_subtask(&task_, name, parent_task);
+ }
+
+ ~ProfileTask()
+ {
+ BLI_profile_task_end(&task_);
+ }
+};
+
+} // namespace blender::profile
+
+#define BLI_PROFILE_SCOPE(name) blender::profile::ProfileTask profile_task((name))
+
+#define BLI_PROFILE_SCOPE_SUBTASK(name, parent_task_ptr) \
+ blender::profile::ProfileTask profile_task((name), (parent_task_ptr))
diff --git a/source/blender/blenlib/BLI_profile_manage.hh b/source/blender/blenlib/BLI_profile_manage.hh
new file mode 100644
index 00000000000..da17598c201
--- /dev/null
+++ b/source/blender/blenlib/BLI_profile_manage.hh
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <chrono>
+#include <string>
+
+#include "BLI_vector.hh"
+
+namespace blender::profile {
+
+using Clock = std::chrono::steady_clock;
+using Duration = Clock::duration;
+using TimePoint = Clock::time_point;
+using Nanoseconds = std::chrono::nanoseconds;
+
+struct ProfileTaskBegin {
+ std::string name;
+ TimePoint time;
+ uint64_t id;
+ uint64_t parent_id;
+ uint64_t thread_id;
+};
+
+struct ProfileTaskEnd {
+ TimePoint time;
+ uint64_t begin_id;
+};
+
+struct RecordedProfile {
+ Vector<ProfileTaskBegin> task_begins;
+ Vector<ProfileTaskEnd> task_ends;
+};
+
+} // namespace blender::profile
More information about the Bf-blender-cvs
mailing list