2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2012-11-05 08:04:57 +00:00
|
|
|
|
|
|
|
|
#ifndef __UTIL_STATS_H__
|
|
|
|
|
#define __UTIL_STATS_H__
|
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/atomic.h"
|
|
|
|
|
#include "util/profiling.h"
|
2014-12-02 15:36:44 +05:00
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
class Stats {
|
|
|
|
|
public:
|
2016-10-24 13:43:55 +02:00
|
|
|
enum static_init_t { static_init = 0 };
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-09 08:47:08 +00:00
|
|
|
Stats() : mem_used(0), mem_peak(0)
|
|
|
|
|
{
|
2016-10-24 13:43:55 +02:00
|
|
|
}
|
|
|
|
|
explicit Stats(static_init_t)
|
2012-11-05 08:04:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
void mem_alloc(size_t size)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2016-11-15 12:16:26 +01:00
|
|
|
atomic_add_and_fetch_z(&mem_used, size);
|
2017-08-23 00:40:04 -04:00
|
|
|
atomic_fetch_and_update_max_z(&mem_peak, mem_used);
|
2012-11-05 08:04:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
void mem_free(size_t size)
|
|
|
|
|
{
|
2014-09-04 17:22:40 +06:00
|
|
|
assert(mem_used >= size);
|
2016-11-15 12:16:26 +01:00
|
|
|
atomic_sub_and_fetch_z(&mem_used, size);
|
2012-11-05 08:04:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
size_t mem_used;
|
|
|
|
|
size_t mem_peak;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif /* __UTIL_STATS_H__ */
|