Blender V4.3
profiler.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_timeit.hh"
6
7#include "DNA_node_types.h"
8
9#include "BKE_node.hh"
10
12
13#include "COM_context.hh"
14#include "COM_profiler.hh"
15
17
22
25{
26 nodes_evaluation_times_.lookup_or_add(node_instance_key, timeit::Nanoseconds::zero()) += time;
27}
28
29timeit::Nanoseconds Profiler::accumulate_node_group_times(const bNodeTree &node_tree,
30 bNodeInstanceKey instance_key)
31{
32 timeit::Nanoseconds tree_evaluation_time = timeit::Nanoseconds::zero();
33
34 for (const bNode *node : node_tree.all_nodes()) {
35 const bNodeInstanceKey node_instance_key = bke::node_instance_key(
36 instance_key, &node_tree, node);
37 if (!node->is_group()) {
38 /* Non-group node, no need to recurse into. Simply accumulate the node's evaluation time to
39 * the current tree's evaluation time. Note that not every node might have an evaluation
40 * time stored, so default to zero. See the documentation on nodes_evaluation_times_ for more
41 * information. */
42 tree_evaluation_time += nodes_evaluation_times_.lookup_default(node_instance_key,
43 timeit::Nanoseconds::zero());
44 continue;
45 }
46
47 const bNodeTree *child_tree = reinterpret_cast<bNodeTree *>(node->id);
48 if (child_tree == nullptr) {
49 /* Node group has lost link to its node tree. For example, due to missing linked file. */
50 continue;
51 }
52
53 const timeit::Nanoseconds group_execution_time = this->accumulate_node_group_times(
54 *child_tree, node_instance_key);
55
56 /* Set evaluation time of the group node. */
57 this->set_node_evaluation_time(node_instance_key, group_execution_time);
58
59 /* Add group evaluation time to the overall tree execution time. */
60 tree_evaluation_time += group_execution_time;
61 }
62
63 return tree_evaluation_time;
64}
65
67{
68 /* Compute the evaluation time of all node groups starting from the root tree. */
69 this->accumulate_node_group_times(node_tree, bke::NODE_INSTANCE_KEY_BASE);
70}
71
72} // namespace blender::realtime_compositor
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:531
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:551
void finalize(const bNodeTree &node_tree)
Definition profiler.cc:66
void set_node_evaluation_time(bNodeInstanceKey node_instance_key, timeit::Nanoseconds time)
Definition profiler.cc:23
Map< bNodeInstanceKey, timeit::Nanoseconds > & get_nodes_evaluation_times()
Definition profiler.cc:18
double time
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE
Definition node.cc:4020
bNodeInstanceKey node_instance_key(bNodeInstanceKey parent_key, const bNodeTree *ntree, const bNode *node)
Definition node.cc:4041
std::chrono::nanoseconds Nanoseconds
Definition BLI_timeit.hh:16