2022-02-11 12:53:21 +00:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#ifndef __UTIL_TIME_H__
|
|
|
|
#define __UTIL_TIME_H__
|
|
|
|
|
2021-10-24 12:19:19 +00:00
|
|
|
#include "util/function.h"
|
|
|
|
#include "util/string.h"
|
2019-03-19 14:19:22 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Give current time in seconds in double precision, with good accuracy. */
|
|
|
|
|
|
|
|
double time_dt();
|
|
|
|
|
2019-03-19 14:19:22 +00:00
|
|
|
/* Sleep for the specified number of seconds. */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
void time_sleep(double t);
|
|
|
|
|
2019-03-19 14:19:22 +00:00
|
|
|
/* Scoped timer. */
|
|
|
|
|
2015-12-30 14:35:21 +00:00
|
|
|
class scoped_timer {
|
|
|
|
public:
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 03:22:34 +00:00
|
|
|
explicit scoped_timer(double *value = NULL) : value_(value)
|
2015-12-30 14:35:21 +00:00
|
|
|
{
|
2016-01-09 23:45:29 +00:00
|
|
|
time_start_ = time_dt();
|
2015-12-30 14:35:21 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-12-30 14:35:21 +00:00
|
|
|
~scoped_timer()
|
|
|
|
{
|
|
|
|
if (value_ != NULL) {
|
2017-08-25 12:15:51 +00:00
|
|
|
*value_ = get_time();
|
2015-12-30 14:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 03:22:34 +00:00
|
|
|
double get_start() const
|
|
|
|
{
|
|
|
|
return time_start_;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-08-25 12:15:51 +00:00
|
|
|
double get_time() const
|
|
|
|
{
|
|
|
|
return time_dt() - time_start_;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-12-30 14:35:21 +00:00
|
|
|
protected:
|
|
|
|
double *value_;
|
|
|
|
double time_start_;
|
|
|
|
};
|
|
|
|
|
2020-10-01 21:16:01 +00:00
|
|
|
class scoped_callback_timer {
|
|
|
|
public:
|
|
|
|
using callback_type = function<void(double)>;
|
|
|
|
|
2023-03-29 14:50:54 +00:00
|
|
|
explicit scoped_callback_timer(callback_type cb) : cb(cb) {}
|
2020-10-01 21:16:01 +00:00
|
|
|
|
|
|
|
~scoped_callback_timer()
|
|
|
|
{
|
|
|
|
if (cb) {
|
|
|
|
cb(timer.get_time());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
scoped_timer timer;
|
|
|
|
callback_type cb;
|
|
|
|
};
|
|
|
|
|
2019-03-19 14:19:22 +00:00
|
|
|
/* Make human readable string from time, compatible with Blender metadata. */
|
|
|
|
|
|
|
|
string time_human_readable_from_seconds(const double seconds);
|
|
|
|
double time_human_readable_to_seconds(const string &str);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|