2017-12-21 16:14:15 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2017 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup depsgraph
|
2017-12-21 16:14:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DEG_depsgraph_debug.h"
|
|
|
|
|
|
2017-12-21 17:16:18 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cstdarg>
|
2017-12-21 16:14:15 +01:00
|
|
|
|
|
|
|
|
#include "BLI_compiler_attrs.h"
|
2017-12-21 17:16:18 +01:00
|
|
|
#include "BLI_math_base.h"
|
2017-12-21 16:14:15 +01:00
|
|
|
|
|
|
|
|
#include "intern/depsgraph.h"
|
2019-01-31 12:56:40 +01:00
|
|
|
#include "intern/node/deg_node_id.h"
|
2017-12-21 16:14:15 +01:00
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
|
|
|
|
|
#define NL "\r\n"
|
|
|
|
|
|
2020-06-29 15:19:56 +02:00
|
|
|
namespace deg = blender::deg;
|
|
|
|
|
|
|
|
|
|
namespace blender {
|
|
|
|
|
namespace deg {
|
2017-12-21 16:14:15 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct DebugContext {
|
2019-04-17 06:17:24 +02:00
|
|
|
FILE *file;
|
|
|
|
|
const Depsgraph *graph;
|
|
|
|
|
const char *label;
|
|
|
|
|
const char *output_filename;
|
2017-12-21 16:14:15 +01:00
|
|
|
};
|
|
|
|
|
|
2017-12-21 17:16:18 +01:00
|
|
|
struct StatsEntry {
|
2019-04-17 06:17:24 +02:00
|
|
|
const IDNode *id_node;
|
|
|
|
|
double time;
|
2017-12-21 17:16:18 +01:00
|
|
|
};
|
|
|
|
|
|
2017-12-21 16:14:15 +01:00
|
|
|
/* TODO(sergey): De-duplicate with graphviz relation debugger. */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void deg_debug_fprintf(const DebugContext &ctx, const char *fmt, ...)
|
|
|
|
|
ATTR_PRINTF_FORMAT(2, 3);
|
2017-12-21 16:14:15 +01:00
|
|
|
static void deg_debug_fprintf(const DebugContext &ctx, const char *fmt, ...)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
vfprintf(ctx.file, fmt, args);
|
|
|
|
|
va_end(args);
|
2017-12-21 16:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_INLINE double get_node_time(const DebugContext & /*ctx*/, const Node *node)
|
2017-12-21 17:16:18 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
// TODO(sergey): Figure out a nice way to define which exact time
|
|
|
|
|
// we want to show.
|
|
|
|
|
return node->stats.current_time;
|
2017-12-21 17:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool stat_entry_comparator(const StatsEntry &a, const StatsEntry &b)
|
2017-12-21 17:16:18 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return a.time > b.time;
|
2017-12-21 17:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
string gnuplotify_id_code(const string &name)
|
2018-08-24 10:16:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return string("") + name[0] + name[1];
|
2018-08-24 10:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
string gnuplotify_name(const string &name)
|
2018-08-24 10:16:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
string result = "";
|
|
|
|
|
const int length = name.length();
|
2019-09-08 00:12:26 +10:00
|
|
|
for (int i = 0; i < length; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
const char ch = name[i];
|
|
|
|
|
if (ch == '_') {
|
|
|
|
|
result += "\\\\\\";
|
|
|
|
|
}
|
|
|
|
|
result += ch;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2018-08-24 10:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void write_stats_data(const DebugContext &ctx)
|
2017-12-21 16:14:15 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
// Fill in array of all stats which are to be displayed.
|
2020-06-10 15:25:39 +02:00
|
|
|
Vector<StatsEntry> stats;
|
2019-04-17 06:17:24 +02:00
|
|
|
stats.reserve(ctx.graph->id_nodes.size());
|
|
|
|
|
for (const IDNode *id_node : ctx.graph->id_nodes) {
|
|
|
|
|
const double time = get_node_time(ctx, id_node);
|
|
|
|
|
if (time == 0.0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
StatsEntry entry;
|
|
|
|
|
entry.id_node = id_node;
|
|
|
|
|
entry.time = time;
|
2020-06-10 15:25:39 +02:00
|
|
|
stats.append(entry);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
// Sort the data.
|
|
|
|
|
std::sort(stats.begin(), stats.end(), stat_entry_comparator);
|
|
|
|
|
// We limit number of entries, otherwise things become unreadable.
|
|
|
|
|
stats.resize(min_ii(stats.size(), 32));
|
|
|
|
|
std::reverse(stats.begin(), stats.end());
|
|
|
|
|
// Print data to the file stream.
|
|
|
|
|
deg_debug_fprintf(ctx, "$data << EOD" NL);
|
|
|
|
|
for (const StatsEntry &entry : stats) {
|
|
|
|
|
deg_debug_fprintf(ctx,
|
|
|
|
|
"\"[%s] %s\",%f" NL,
|
|
|
|
|
gnuplotify_id_code(entry.id_node->id_orig->name).c_str(),
|
|
|
|
|
gnuplotify_name(entry.id_node->id_orig->name + 2).c_str(),
|
|
|
|
|
entry.time);
|
|
|
|
|
}
|
|
|
|
|
deg_debug_fprintf(ctx, "EOD" NL);
|
2017-12-21 16:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void deg_debug_stats_gnuplot(const DebugContext &ctx)
|
2017-12-21 16:14:15 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
// Data itself.
|
|
|
|
|
write_stats_data(ctx);
|
|
|
|
|
// Optional label.
|
|
|
|
|
if (ctx.label && ctx.label[0]) {
|
|
|
|
|
deg_debug_fprintf(ctx, "set title \"%s\"" NL, ctx.label);
|
|
|
|
|
}
|
|
|
|
|
// Rest of the commands.
|
|
|
|
|
// TODO(sergey): Need to decide on the resolution somehow.
|
|
|
|
|
deg_debug_fprintf(ctx, "set terminal pngcairo size 1920,1080" NL);
|
|
|
|
|
deg_debug_fprintf(ctx, "set output \"%s\"" NL, ctx.output_filename);
|
|
|
|
|
deg_debug_fprintf(ctx, "set grid" NL);
|
|
|
|
|
deg_debug_fprintf(ctx, "set datafile separator ','" NL);
|
|
|
|
|
deg_debug_fprintf(ctx, "set style fill solid" NL);
|
|
|
|
|
deg_debug_fprintf(ctx,
|
|
|
|
|
"plot \"$data\" using "
|
|
|
|
|
"($2*0.5):0:($2*0.5):(0.2):yticlabels(1) "
|
|
|
|
|
"with boxxyerrorbars t '' lt rgb \"#406090\"" NL);
|
2017-12-21 16:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
2020-06-29 15:19:56 +02:00
|
|
|
} // namespace deg
|
|
|
|
|
} // namespace blender
|
2017-12-21 16:14:15 +01:00
|
|
|
|
|
|
|
|
void DEG_debug_stats_gnuplot(const Depsgraph *depsgraph,
|
|
|
|
|
FILE *f,
|
|
|
|
|
const char *label,
|
|
|
|
|
const char *output_filename)
|
|
|
|
|
{
|
2020-01-28 14:50:13 +01:00
|
|
|
if (depsgraph == nullptr) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-06-29 15:19:56 +02:00
|
|
|
deg::DebugContext ctx;
|
2019-04-17 06:17:24 +02:00
|
|
|
ctx.file = f;
|
2020-06-29 15:19:56 +02:00
|
|
|
ctx.graph = (deg::Depsgraph *)depsgraph;
|
2019-04-17 06:17:24 +02:00
|
|
|
ctx.label = label;
|
|
|
|
|
ctx.output_filename = output_filename;
|
2020-06-29 15:19:56 +02:00
|
|
|
deg::deg_debug_stats_gnuplot(ctx);
|
2017-12-21 16:14:15 +01:00
|
|
|
}
|