2012-11-05 08:04:57 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2012-11-05 08:04:57 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-11-05 08:04:57 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-05 08:04:57 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2012-11-05 08:04:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UTIL_STATS_H__
|
|
|
|
#define __UTIL_STATS_H__
|
|
|
|
|
2014-12-02 10:36:44 +00:00
|
|
|
#include "util_atomic.h"
|
|
|
|
|
2012-11-05 08:04:57 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Stats {
|
|
|
|
public:
|
2012-11-09 08:47:08 +00:00
|
|
|
Stats() : mem_used(0), mem_peak(0) {}
|
2012-11-05 08:04:57 +00:00
|
|
|
|
|
|
|
void mem_alloc(size_t size) {
|
2014-12-02 10:36:44 +00:00
|
|
|
atomic_add_z(&mem_used, size);
|
|
|
|
atomic_update_max_z(&mem_peak, mem_used);
|
2012-11-05 08:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mem_free(size_t size) {
|
2014-09-04 11:22:40 +00:00
|
|
|
assert(mem_used >= size);
|
2014-12-02 10:36:44 +00:00
|
|
|
atomic_sub_z(&mem_used, size);
|
2012-11-05 08:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t mem_used;
|
|
|
|
size_t mem_peak;
|
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __UTIL_STATS_H__ */
|