[Bf-blender-cvs] [6951661dccc] profiler-editor: fix stack
Jacques Lucke
noreply at git.blender.org
Thu Apr 29 11:30:49 CEST 2021
Commit: 6951661dccc51d8c470f29c1977f413989ca14ad
Author: Jacques Lucke
Date: Tue Apr 27 18:19:16 2021 +0200
Branches: profiler-editor
https://developer.blender.org/rB6951661dccc51d8c470f29c1977f413989ca14ad
fix stack
===================================================================
M source/blender/blenkernel/intern/DerivedMesh.cc
M source/blender/blenlib/BLI_profile.h
M source/blender/blenlib/intern/profile.cc
M source/blender/editors/space_profiler/profiler_draw.cc
M source/blender/editors/space_profiler/profiler_layout.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 474bfd0a4ee..f3c6d9f9687 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -924,7 +924,7 @@ static Mesh *modifier_modify_mesh_and_geometry_set(ModifierData *md,
Mesh *input_mesh,
GeometrySet &geometry_set)
{
- BLI_PROFILE_SCOPE(__func__);
+ BLI_PROFILE_SCOPE(md->name);
Mesh *mesh_output = nullptr;
const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md->type);
if (mti->modifyGeometrySet == nullptr) {
diff --git a/source/blender/blenlib/BLI_profile.h b/source/blender/blenlib/BLI_profile.h
index 5826c5c84da..595cd7e122b 100644
--- a/source/blender/blenlib/BLI_profile.h
+++ b/source/blender/blenlib/BLI_profile.h
@@ -28,6 +28,8 @@ typedef struct BLI_ProfileTask {
uint64_t id;
} BLI_ProfileTask;
+#define BLI_PROFILE_DUMMY_ID (~0)
+
BLI_INLINE bool BLI_profile_is_enabled(void)
{
return bli_profiling_is_enabled;
@@ -43,16 +45,22 @@ void _bli_profile_task_end(BLI_ProfileTask *task);
if (bli_profiling_is_enabled) { \
_bli_profile_task_begin((task_ptr), (name)); \
} \
+ else { \
+ (task_ptr)->id = BLI_PROFILE_DUMMY_ID; \
+ } \
((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)); \
} \
+ else { \
+ (task_ptr)->id = BLI_PROFILE_DUMMY_ID; \
+ } \
((void)0)
#define BLI_profile_task_end(task_ptr) \
- if (bli_profiling_is_enabled) { \
+ if (bli_profiling_is_enabled && (task_ptr)->id != BLI_PROFILE_DUMMY_ID) { \
_bli_profile_task_end(task_ptr); \
} \
((void)0)
diff --git a/source/blender/blenlib/intern/profile.cc b/source/blender/blenlib/intern/profile.cc
index 9b265a61093..ac427ac3708 100644
--- a/source/blender/blenlib/intern/profile.cc
+++ b/source/blender/blenlib/intern/profile.cc
@@ -116,41 +116,56 @@ void ProfileListener::flush_to_all()
void _bli_profile_task_begin(BLI_ProfileTask *task, const char *name)
{
- task->id = get_unique_session_id();
+ ThreadLocalProfileData &local_data = threadlocal_profile_data;
- ProfileTaskBegin *task_begin = threadlocal_profile_data.queue_begins.prepare_append();
- task_begin->id = task->id;
+ const uint64_t id = get_unique_session_id();
+ const uint64_t parent_id = local_data.id_stack.peek_default(0);
+ local_data.id_stack.push(id);
+ task->id = id;
+
+ ProfileTaskBegin *task_begin = local_data.queue_begins.prepare_append();
+ task_begin->id = id;
task_begin->name = name;
- task_begin->parent_id = threadlocal_profile_data.id_stack.peek_default(0);
- task_begin->thread_id = threadlocal_profile_data.thread_id;
+ task_begin->parent_id = parent_id;
+ task_begin->thread_id = local_data.thread_id;
task_begin->time = Clock::now();
- threadlocal_profile_data.queue_begins.commit_append();
+ local_data.queue_begins.commit_append();
}
void _bli_profile_task_begin_subtask(BLI_ProfileTask *task,
const char *name,
const BLI_ProfileTask *parent_task)
{
- task->id = get_unique_session_id();
+ ThreadLocalProfileData &local_data = threadlocal_profile_data;
+
+ const uint64_t id = get_unique_session_id();
+ const uint64_t parent_id = local_data.id_stack.peek_default(0);
+ local_data.id_stack.push(id);
+ task->id = id;
- ProfileTaskBegin *task_begin = threadlocal_profile_data.queue_begins.prepare_append();
- task_begin->id = task->id;
+ ProfileTaskBegin *task_begin = local_data.queue_begins.prepare_append();
+ task_begin->id = id;
task_begin->name = name;
- task_begin->parent_id = parent_task->id;
- task_begin->thread_id = threadlocal_profile_data.thread_id;
+ task_begin->parent_id = parent_id;
+ task_begin->thread_id = local_data.thread_id;
task_begin->time = Clock::now();
- threadlocal_profile_data.queue_begins.commit_append();
+ local_data.queue_begins.commit_append();
}
void _bli_profile_task_end(BLI_ProfileTask *task)
{
TimePoint time = Clock::now();
- ProfileTaskEnd *task_end = threadlocal_profile_data.queue_ends.prepare_append();
+ ThreadLocalProfileData &local_data = threadlocal_profile_data;
+
+ BLI_assert(local_data.id_stack.peek() == task->id);
+ local_data.id_stack.pop();
+
+ ProfileTaskEnd *task_end = local_data.queue_ends.prepare_append();
task_end->begin_id = task->id;
task_end->time = time;
- threadlocal_profile_data.queue_ends.commit_append();
+ local_data.queue_ends.commit_append();
}
diff --git a/source/blender/editors/space_profiler/profiler_draw.cc b/source/blender/editors/space_profiler/profiler_draw.cc
index 42f4e7c48f2..7bad79d28e8 100644
--- a/source/blender/editors/space_profiler/profiler_draw.cc
+++ b/source/blender/editors/space_profiler/profiler_draw.cc
@@ -48,6 +48,7 @@ class ProfilerDrawer {
ProfilerLayout *profiler_layout_;
int row_height_;
int parallel_padding_;
+ uiBlock *ui_block_ = nullptr;
public:
ProfilerDrawer(const bContext *C, ARegion *region) : C(C), region_(region)
@@ -68,8 +69,13 @@ class ProfilerDrawer {
void draw()
{
UI_ThemeClearColor(TH_BACK);
+
this->compute_vertical_extends_of_all_nodes();
+
+ ui_block_ = UI_block_begin(C, region_, __func__, UI_EMBOSS_NONE);
this->draw_all_nodes();
+ UI_block_end(C, ui_block_);
+ UI_block_draw(C, ui_block_);
}
void compute_vertical_extends_of_all_nodes()
@@ -97,8 +103,10 @@ class ProfilerDrawer {
node.bottom_y = node.top_y - row_height_;
node.bottom_y = this->compute_vertical_extends_of_nodes(node.direct_children(), node.bottom_y);
for (Span<ProfileNode *> children : node.parallel_children()) {
- node.bottom_y -= parallel_padding_;
- node.bottom_y = this->compute_vertical_extends_of_nodes(children, node.bottom_y);
+ if (!children.is_empty()) {
+ node.bottom_y -= parallel_padding_;
+ node.bottom_y = this->compute_vertical_extends_of_nodes(children, node.bottom_y);
+ }
}
}
@@ -131,6 +139,37 @@ class ProfilerDrawer {
immRecti(pos, left_x, node.top_y, right_x, node.bottom_y);
immUnbindProgram();
+
+ this->draw_node_label(node, left_x, right_x);
+
+ this->draw_nodes(node.direct_children());
+ for (Span<ProfileNode *> nodes : node.parallel_children()) {
+ this->draw_nodes(nodes);
+ }
+ }
+
+ void draw_node_label(ProfileNode &node, const int left_x, const int right_x)
+ {
+ const int x = std::max(0, left_x);
+ const int width = std::max(1, std::min<int>(right_x, region_->winx) - x);
+
+ uiBut *but = uiDefIconTextBut(ui_block_,
+ UI_BTYPE_LABEL,
+ 0,
+ ICON_NONE,
+ node.name().c_str(),
+ x,
+ node.top_y - row_height_,
+ width,
+ row_height_,
+ nullptr,
+ 0,
+ 0,
+ 0,
+ 0,
+ nullptr);
+ UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT);
+ UI_but_drawflag_disable(but, UI_BUT_TEXT_RIGHT);
}
int time_to_x(const TimePoint time) const
@@ -143,7 +182,7 @@ class ProfilerDrawer {
Color4f get_node_color(ProfileNode &node)
{
- const uint64_t value = node.begin_time().time_since_epoch().count();
+ const uint64_t value = POINTER_AS_UINT(&node);
const float variation = BLI_hash_int_2d_to_float(value, value >> 32);
float r, g, b;
hsv_to_rgb(variation * 0.2f, 0.5f, 0.5f, &r, &g, &b);
diff --git a/source/blender/editors/space_profiler/profiler_layout.cc b/source/blender/editors/space_profiler/profiler_layout.cc
index ec816e7d86b..c050b24ce67 100644
--- a/source/blender/editors/space_profiler/profiler_layout.cc
+++ b/source/blender/editors/space_profiler/profiler_layout.cc
@@ -31,11 +31,12 @@ bool ProfileNode::time_overlap(const ProfileNode &a, const ProfileNode &b)
}
template<typename UseNodeF>
-static int try_pack_into_vector(Vector<ProfileNode *> &sorted_nodes_vec,
- MutableSpan<ProfileNode *> sorted_nodes_to_pack,
- const UseNodeF &use_node_fn)
+static bool try_pack_into_vector(Vector<ProfileNode *> &sorted_nodes_vec,
+ MutableSpan<ProfileNode *> sorted_nodes_to_pack,
+ const UseNodeF &use_node_fn)
{
- int tot_newly_inserted = 0;
+ bool packed_everything = true;
+
MutableSpan<ProfileNode *> remaining_existing = sorted_nodes_vec;
MutableSpan<ProfileNode *> remaining_new = sorted_nodes_to_pack;
Vector<ProfileNode *> new_vec;
@@ -56,13 +57,13 @@ static int try_pack_into_vector(Vector<ProfileNode *> &sorted_nodes_vec,
if (ProfileNode::time_overlap(*existing_child, *new_child)) {
/* Node collides with previously added node. */
remaining_new = remaining_new.drop_front(1);
+ packed_everything = false;
break;
}
}
if (remaining_existing.is_empty()) {
/* There are no remaining existing nodes the new child can collide with. */
new_vec.append(new_child);
- tot_newly_inserted++;
remaining_new[0] = nullptr;
remaining_new = remaining_new.drop_front(1);
break;
@@ -79,12 +80,12 @@ static int try_pack_into_vector(Vector<ProfileNode *> &sorted_nodes_vec,
new_vec.append(existing_child);
remaining_existing = remaining_existing.drop_front(1);
remaining_new = remaining_new.drop_front(1);
+ packed_everything = false;
break;
}
if (new_child->end_time() <= existing_child->begin_time()) {
/* New child can be added safely. */
new_vec.append(new_child);
- tot_n
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list