21#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
25#define _POSIX_C_SOURCE 200809L
48#include <profileapi.h>
52#ifdef KOLISEO_HAS_LOCATE
53typedef struct Koliseo_Loc {
59#define KLS_HERE (Koliseo_Loc){ \
69#define KLS_Loc_Fmt "[%s:%i at %s():] "
75#define KLS_Loc_Arg(loc) (loc.file), (loc.line), (loc.func)
82typedef void*(kls_alloc_func)(
size_t);
84#define STRINGIFY_2(x) #x
86#define STRINGIFY(x) STRINGIFY_2(x)
88#ifdef KOLISEO_HAS_REGION
94typedef enum KLS_RegList_Alloc_Backend {
95 KLS_REGLIST_ALLOC_LIBC = 0,
96 KLS_REGLIST_ALLOC_KLS_BASIC,
97 KLS_REGLIST_TOTAL_BACKENDS
98} KLS_RegList_Alloc_Backend;
118static const int KOLISEO_API_VERSION_INT =
119 (KLS_MAJOR * 1000000 + KLS_MINOR * 10000 + KLS_PATCH * 100);
125static const char KOLISEO_API_VERSION_STRING[] =
"0.4.8";
137#define KLS_DEFAULT_SIZE (16*1024)
139#ifndef KLS_DEFAULT_ALIGNMENT
140#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *))
147typedef enum KLS_Region_Type {
157#define KLS_REGIONTYPE_MAX KLS_Header
163#define KLS_REGION_MAX_NAME_SIZE 15
168#define KLS_REGION_MAX_DESC_SIZE 20
170#ifdef KOLISEO_HAS_REGION
177typedef struct KLS_Region {
178 ptrdiff_t begin_offset;
179 ptrdiff_t end_offset;
182 char name[KLS_REGION_MAX_NAME_SIZE + 1];
183 char desc[KLS_REGION_MAX_DESC_SIZE + 1];
187static const char KOLISEO_DEFAULT_REGION_NAME[] =
"No Name";
188static const char KOLISEO_DEFAULT_REGION_DESC[] =
"No Desc";
190typedef KLS_Region *KLS_list_element;
196typedef struct KLS_list_region {
197 KLS_list_element value;
198 struct KLS_list_region *next;
199} KLS_region_list_item;
201typedef KLS_region_list_item *KLS_Region_List;
207#ifndef KOLISEO_HAS_LOCATE
208typedef void(KLS_OOM_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count);
210typedef void(KLS_OOM_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
213#ifndef KOLISEO_HAS_LOCATE
214typedef void(KLS_PTRDIFF_MAX_Handler)(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count);
216typedef void(KLS_PTRDIFF_MAX_Handler)(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
219#ifndef KOLISEO_HAS_LOCATE
220typedef void(KLS_ZEROCOUNT_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size);
222typedef void(KLS_ZEROCOUNT_Handler)(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc);
225#ifndef KOLISEO_HAS_LOCATE
226void KLS_OOM_default_handler__(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count);
228void KLS_OOM_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
231#ifndef KOLISEO_HAS_LOCATE
234void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
237#ifndef KOLISEO_HAS_LOCATE
240void KLS_ZEROCOUNT_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc);
247typedef struct KLS_Err_Handlers {
248 KLS_OOM_Handler* OOM_handler;
249 KLS_PTRDIFF_MAX_Handler* PTRDIFF_MAX_handler;
250 KLS_ZEROCOUNT_Handler* ZEROCOUNT_handler;
253#ifndef KOLISEO_HAS_LOCATE
254#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler__, }
256#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler_dbg__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__, }
263typedef struct KLS_Conf {
264#ifdef KOLISEO_HAS_REGION
265 int kls_autoset_regions;
266 KLS_RegList_Alloc_Backend kls_reglist_alloc_backend;
267 ptrdiff_t kls_reglist_kls_size;
268 int kls_autoset_temp_regions;
270 int kls_collect_stats;
273 const char *kls_log_filepath;
274 int kls_block_while_has_temp;
275 int kls_allow_zerocount_push;
276 KLS_Err_Handlers err_handlers;
279KLS_Conf
kls_conf_init_handled(
int autoset_regions,
int alloc_backend, ptrdiff_t reglist_kls_size,
int autoset_temp_regions,
int collect_stats,
int verbose_lvl,
int block_while_has_temp,
int allow_zerocount_push, FILE* log_fp,
const char* log_filepath, KLS_Err_Handlers err_handlers);
281KLS_Conf
kls_conf_init(
int autoset_regions,
int alloc_backend, ptrdiff_t reglist_kls_size,
int autoset_temp_regions,
int collect_stats,
int verbose_lvl,
int block_while_has_temp,
int allow_zerocount_push, FILE* log_fp,
const char* log_filepath);
289typedef struct KLS_Stats {
296#ifdef KOLISEO_HAS_REGION
297 ptrdiff_t avg_region_size;
300 double worst_pushcall_time;
322#ifdef KOLISEO_HAS_REGION
324#define KLS_Conf_Fmt "KLS_Conf { autoset_regions: %i, reglist_backend: %s, reglist_kls_size: %li, autoset_temp_regions: %i, collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p, block_while_has_temp: %i, allow_zerocount_push: %i }"
326#define KLS_Conf_Fmt "KLS_Conf { autoset_regions: %i, reglist_backend: %s, reglist_kls_size: %lli, autoset_temp_regions: %i, collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p, block_while_has_temp: %i, allow_zerocount_push: %i }"
330#define KLS_Conf_Fmt "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p, block_while_has_temp: %i, allow_zerocount_push: %i }"
337#ifdef KOLISEO_HAS_REGION
338#define KLS_Conf_Arg(conf) (conf.kls_autoset_regions),kls_reglist_backend_string((conf.kls_reglist_alloc_backend)),(conf.kls_reglist_kls_size),(conf.kls_autoset_temp_regions),(conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp),(conf.kls_block_while_has_temp),(conf.kls_allow_zerocount_push)
340#define KLS_Conf_Arg(conf) (conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp),(conf.kls_block_while_has_temp),(conf.kls_allow_zerocount_push)
347#ifdef KOLISEO_HAS_REGION
352#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %li, tot_hiccups: %i, worst_push_time: %.9f }"
354#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %li, tot_hiccups: %i }"
360#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %lli, tot_hiccups: %i, worst_push_time: %.7f }"
362#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, avg_region_size: %lli, tot_hiccups: %i }"
369#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i, worst_push_time: %.7f }"
371#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i }"
380#ifdef KOLISEO_HAS_REGION
382#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.avg_region_size),(stats.tot_hiccups),(stats.worst_pushcall_time)
384#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.avg_region_size),(stats.tot_hiccups)
388#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups),(stats.worst_pushcall_time)
390#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups)
394#ifdef KOLISEO_HAS_REGION
401typedef struct KLS_Temp_Conf {
402 int kls_autoset_regions;
403 KLS_RegList_Alloc_Backend tkls_reglist_alloc_backend;
404 ptrdiff_t kls_reglist_kls_size;
413#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %li}"
415#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %lli}"
422#define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size)
432typedef struct Koliseo {
436 ptrdiff_t prev_offset;
437#ifdef KOLISEO_HAS_REGION
438 KLS_Region_List regs;
439 struct Koliseo *reglist_kls;
440 int max_regions_kls_alloc_basic;
445 struct Koliseo_Temp *t_kls;
453#define KLSFmt "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
455#define KLSFmt "KLS {begin: %p, curr: %p, size: %lli, offset: %lli, has_temp: %i}"
462#define KLS_Arg(kls) (void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)
471typedef struct Koliseo_Temp {
474 ptrdiff_t prev_offset;
475#ifdef KOLISEO_HAS_REGION
476 KLS_Region_List t_regs;
477 Koliseo *reglist_kls;
478 int max_regions_kls_alloc_basic;
483void kls_log(Koliseo * kls,
const char *tag,
const char *format, ...);
486#ifdef KOLISEO_HAS_REGION
491#ifndef KOLISEO_HAS_LOCATE
492Koliseo *
kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
494Koliseo *kls_new_alloc_dbg(ptrdiff_t size, kls_alloc_func alloc_func, Koliseo_Loc loc);
495#define kls_new_alloc(size, alloc_func) kls_new_alloc_dbg((size), (alloc_func), KLS_HERE)
498#ifndef KLS_DEFAULT_ALLOCF
499#define KLS_DEFAULT_ALLOCF malloc
502#define kls_new(size) kls_new_alloc((size), KLS_DEFAULT_ALLOCF)
505#define kls_new_conf(size, conf) kls_new_conf_alloc((size), (conf), KLS_DEFAULT_ALLOCF)
506Koliseo *
kls_new_traced_alloc_handled(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
507Koliseo *
kls_new_traced_alloc(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func);
508#define kls_new_traced(size, output_path) kls_new_traced_alloc((size), (output_path), KLS_DEFAULT_ALLOCF)
509#define kls_new_traced_handled(size, output_path, err_handlers) kls_new_traced_alloc_handled((size), (output_path), KLS_DEFAULT_ALLOCF, (err_handlers))
512#define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF)
513#define kls_new_dbg_handled(size, err_handlers) kls_new_dbg_alloc_handled((size), KLS_DEFAULT_ALLOCF,(err_handlers))
515 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
517 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func);
518#define kls_new_traced_AR_KLS(size, output_path, reglist_kls_size) kls_new_traced_AR_KLS_alloc((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF)
519#define kls_new_traced_AR_KLS_handled(size, output_path, reglist_kls_size, err_handlers) kls_new_traced_AR_KLS_alloc_handled((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF, (err_handlers))
523#ifndef KOLISEO_HAS_LOCATE
524void *
kls_push_zero(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
527void *kls_push_zero_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
528 ptrdiff_t count, Koliseo_Loc loc);
530#define kls_push_zero(kls, size, align, count) kls_push_zero_dbg((kls), (size), (align), (count), KLS_HERE)
533#ifndef KOLISEO_HAS_LOCATE
537void *kls_push_zero_AR_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
538 ptrdiff_t count, Koliseo_Loc loc);
539#define kls_push_zero_AR(kls, size, align, count) kls_push_zero_AR_dbg((kls), (size), (align), (count), KLS_HERE)
542#ifdef KOLISEO_HAS_REGION
544#ifndef KOLISEO_HAS_LOCATE
546 ptrdiff_t count,
char *name,
char *desc);
548void *kls_push_zero_named_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
549 ptrdiff_t count,
char *name,
char *desc, Koliseo_Loc loc);
550#define kls_push_zero_named(kls, size, align, count, name, desc) kls_push_zero_named_dbg((kls), (size), (align), (count), (name), (desc), KLS_HERE)
553#ifndef KOLISEO_HAS_LOCATE
555 ptrdiff_t count,
int type,
char *name,
char *desc);
557void *kls_push_zero_typed_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
558 ptrdiff_t count,
int type,
char *name,
char *desc, Koliseo_Loc loc);
559#define kls_push_zero_typed(kls, size, align, count, type, name, desc) kls_push_zero_typed_dbg((kls), (size), (align), (count), (type), (name), (desc), KLS_HERE)
566#define KLS_PUSH_ARR(kls, type, count) (type*)kls_push_zero_AR((kls), sizeof(type), _Alignof(type), (count))
572#define KLS_PUSH_STR(kls, cstr) KLS_PUSH_ARR((kls), char, strlen((cstr))+1)
577#ifdef KOLISEO_HAS_REGION
578#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named((kls), sizeof(type), _Alignof(type), (count), (name), (desc))
580#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) KLS_PUSH_ARR((kls),type,(count))
586#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc) KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr))+1, (name), (desc))
591#ifdef KOLISEO_HAS_REGION
592#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) (type*)kls_push_zero_typed((kls), sizeof(type), _Alignof(type), (count), (region_type), (name), (desc))
594#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) KLS_PUSH_ARR((kls),type,(count))
600#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr))+1, (region_type), (name), (desc))
605#define KLS_PUSH(kls, type) KLS_PUSH_ARR((kls), type, 1)
610#define KLS_PUSH_NAMED(kls, type, name, desc) KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
616#define KLS_PUSH_EX(kls, type, name) KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
621#define KLS_PUSH_TYPED(kls, type, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))
627#define KLS_PUSH_TYPED_EX(kls, type, region_type, name) KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
633void kls_formatSize(ptrdiff_t size,
char *outputBuffer,
size_t bufferSize);
635#ifndef KOLISEO_HAS_LOCATE
638Koliseo_Temp *kls_temp_start_dbg(Koliseo * kls, Koliseo_Loc loc);
639#define kls_temp_start(kls) kls_temp_start_dbg((kls), KLS_HERE)
644#ifndef KOLISEO_HAS_LOCATE
646 ptrdiff_t align, ptrdiff_t count);
648void *kls_temp_push_zero_AR_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
649 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc);
650#define kls_temp_push_zero_AR(t_kls, size, align, count) kls_temp_push_zero_AR_dbg((t_kls), (size), (align), (count), KLS_HERE)
653#ifdef KOLISEO_HAS_REGION
654#ifndef KOLISEO_HAS_LOCATE
656 ptrdiff_t align, ptrdiff_t count,
char *name,
659void *kls_temp_push_zero_named_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
660 ptrdiff_t align, ptrdiff_t count,
char *name,
661 char *desc, Koliseo_Loc loc);
662#define kls_temp_push_zero_named(t_kls, size, align, count, name, desc) kls_temp_push_zero_named_dbg((t_kls), (size), (align), (count), (name), (desc), KLS_HERE)
665#ifndef KOLISEO_HAS_LOCATE
667 ptrdiff_t align, ptrdiff_t count,
int type,
668 char *name,
char *desc);
670void *kls_temp_push_zero_typed_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
671 ptrdiff_t align, ptrdiff_t count,
int type,
672 char *name,
char *desc, Koliseo_Loc loc);
673#define kls_temp_push_zero_typed(t_kls, size, align, count, type, name, desc) kls_temp_push_zero_typed_dbg((t_kls), (size), (align), (count), (type), (name), (desc), KLS_HERE)
682#define KLS_PUSH_ARR_T(kls_temp, type, count) (type*)kls_temp_push_zero_AR((kls_temp), sizeof(type), _Alignof(type), (count))
688#define KLS_PUSH_STR_T(kls_temp, cstr) KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)
693#ifdef KOLISEO_HAS_REGION
694#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) (type*)kls_temp_push_zero_named((kls_temp), sizeof(type), _Alignof(type), (count), (name), (desc))
696#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
702#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr))+1, (name), (desc))
707#ifdef KOLISEO_HAS_REGION
708#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)kls_temp_push_zero_typed((kls_temp), sizeof(type), _Alignof(type), (count), (region_type), (name), (desc))
710#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
716#define KLS_PUSH_STR_T_TYPED(kls_temp, cstr, region_type, name, desc) KLS_PUSH_ARR_T_TYPED((kls_temp), char, strlen((cstr))+1, (region_type), (name), (desc))
721#define KLS_PUSH_T(kls_temp, type) KLS_PUSH_ARR_T((kls_temp), type, 1)
726#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))
732#define KLS_PUSH_T_EX(kls_temp, type, name) KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
737#define KLS_PUSH_T_TYPED(kls_temp, type, region_type, name, desc) KLS_PUSH_ARR_T_TYPED((kls_temp), type, 1, (region_type), (name), (desc))
743#define KLS_PUSH_T_TYPED_EX(kls_temp, type, region_type, name) KLS_PUSH_T_TYPED((kls_temp), type, (region_type), (name), STRINFIGY(type))
745#ifdef KOLISEO_HAS_REGION
748#define KLS_RL_GETLIST() kls_rl_emptyList()
752KLS_Region_List
kls_rl_cons(Koliseo *, KLS_list_element, KLS_Region_List);
753#ifdef KOLISEO_HAS_EXPER
754KLS_region_list_item* kls_rl_list_pop(Koliseo *kls);
756KLS_Region_List
kls_rl_t_cons(Koliseo_Temp *, KLS_list_element, KLS_Region_List);
757#ifdef KOLISEO_HAS_EXPER
758KLS_region_list_item* kls_rl_t_list_pop(Koliseo_Temp *t_kls);
762#define KLS_RL_FREELIST(kls_list) kls_rl_freeList(kls_list)
764#define kls_showList(list) kls_rl_showList((list))
766#define kls_showList_toFile(list, fp) kls_rl_showList_toFile((list), (fp))
767#define KLS_RL_ECHOLIST(kls_list) kls_rl_showList(kls_list)
768#define KLS_RL_PRINTLIST(kls_list,file) kls_rl_showList_toFile(kls_list,file)
771KLS_Region_List
kls_rl_append(Koliseo *, KLS_Region_List, KLS_Region_List);
773KLS_Region_List
kls_rl_copy(Koliseo *, KLS_Region_List);
774KLS_Region_List
kls_rl_delete(Koliseo *, KLS_list_element, KLS_Region_List);
776KLS_Region_List
kls_rl_insord(Koliseo *, KLS_list_element, KLS_Region_List);
777#define KLS_RL_PUSHLIST(kls,reg,kls_list) kls_rl_insord(kls,reg,kls_list)
778KLS_Region_List
kls_rl_insord_p(Koliseo *, KLS_list_element, KLS_Region_List);
779#define KLS_RL_PUSHLIST_P(kls,reg,kls_list) kls_rl_insord_p(kls,reg,kls_list)
780KLS_Region_List
kls_rl_mergeList(Koliseo *, KLS_Region_List, KLS_Region_List);
781KLS_Region_List
kls_rl_intersect(Koliseo *, KLS_Region_List, KLS_Region_List);
782KLS_Region_List
kls_rl_diff(Koliseo *, KLS_Region_List, KLS_Region_List);
784#define KLS_RL_DIFF(kls,kls_list1,kls_list2) kls_rl_diff(kls,kls_list1,kls_list2)
797#ifdef KOLISEO_HAS_GULP
802#ifndef KOLISEO_GULP_H_
803#define KOLISEO_GULP_H_
826#define KSTR(c_lit) kstr_new(c_lit, sizeof(c_lit) - 1)
827#define KSTR_NULL kstr_new(NULL, 0)
832#define Kstr_Fmt "%.*s"
836#define Kstr_Arg(kstr) (int) (kstr.len), (kstr.data)
845#define ONEGB_DEC_INT 1073741824
851#define GULP_MAX_FILE_SIZE ONEGB_DEC_INT
870#define Gulp_Res_Fmt "%s"
874#define Gulp_Res_Arg(gr) (string_from_Gulp_Res((gr)))
886#define KLS_GULP_FILE(kls, filepath) try_kls_gulp_file((kls),(filepath), GULP_MAX_FILE_SIZE)
890#define KLS_GULP_FILE_KSTR(kls, filepath) try_kls_gulp_file_to_kstr((kls),(filepath), GULP_MAX_FILE_SIZE, false)
896#ifdef KOLISEO_HAS_EXPER
898void *
kls_pop(Koliseo * kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
899void *
kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
905#define KLS_POP_ARR(kls, type, count) (type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
911#define KLS_POP_STR(kls, cstr) KLS_POP_ARR((kls), char, strlen((cstr)))
917#define KLS_POP(kls, type) KLS_POP_ARR((kls), type, 1)
919void *
kls_temp_pop(Koliseo_Temp * t_kls, ptrdiff_t size, ptrdiff_t align,
921void *
kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
927#define KLS_POP_ARR_T(kls_temp, type, count) (type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
933#define KLS_POP_STR_T(kls_temp, cstr) KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
939#define KLS_POP_T(kls_temp, type) KLS_POP_ARR_T((kls_temp), type, 1)
951#define KLS__STRCPY(dest, source) do {\
952 strcpy((dest), (source));\
960#define KLS_STRDUP(kls, source) kls_strdup((kls), (source))
970#define KLS_STRDUP_T(t_kls, source) kls_t_strdup((t_kls), (source))
975#error "This code requires C11 or later.\n _Alignof() is not available"
const char * string_from_Gulp_Res(Gulp_Res g)
Return a constant string for the passed Gulp_Res.
Definition koliseo.c:3285
Kstr * kls_gulp_file_sized_to_kstr(Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size, bool allow_nullchar)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3763
bool kstr_try_token(Kstr *k, char delim, Kstr *part)
Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer ...
Definition koliseo.c:3476
Kstr kstr_trim_left(Kstr kstr)
Returns a new Kstr after removing heading spaces from the passed one.
Definition koliseo.c:3405
bool kstr_eq_ignorecase(Kstr left, Kstr right)
Checks if the two passed Kstr have equal data, ignoring case.
Definition koliseo.c:3343
char * kls_gulp_file_sized(Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3623
Kstr kstr_trim_right(Kstr kstr)
Returns a new Kstr after removing trailing spaces from the passed one.
Definition koliseo.c:3420
Kstr * try_kls_gulp_file_to_kstr(Koliseo *kls, const char *filepath, size_t max_size, bool allow_nullchar)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3805
char * try_kls_gulp_file(Koliseo *kls, const char *filepath, size_t max_size)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3664
Kstr kstr_cut_r(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the right.
Definition koliseo.c:3388
Kstr kstr_from_c_lit(const char *c_lit)
Returns a new Kstr from the passed null-terminated string.
Definition koliseo.c:3312
Kstr kstr_cut_l(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the left.
Definition koliseo.c:3369
Kstr kstr_new(const char *str, size_t len)
Returns a new Kstr with the passed args set.
Definition koliseo.c:3298
Kstr kstr_token(Kstr *k, char delim)
Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not presen...
Definition koliseo.c:3504
Kstr kstr_trim(Kstr kstr)
Returns a new Kstr after removing heading and trailing spaces from the passed one.
Definition koliseo.c:3437
Kstr kstr_token_kstr(Kstr *k, Kstr delim)
Definition koliseo.c:3524
Gulp_Res
Defines possible results for kls_gulp_file_sized().
Definition kls_gulp.h:77
@ TOT_GULP_RES
Definition kls_gulp.h:84
@ GULP_FILE_KLS_NULL
Definition kls_gulp.h:83
@ GULP_FILE_CONTAINS_NULLCHAR
Definition kls_gulp.h:82
@ GULP_FILE_NOT_EXIST
Definition kls_gulp.h:79
@ GULP_FILE_TOO_LARGE
Definition kls_gulp.h:80
@ GULP_FILE_OK
Definition kls_gulp.h:78
@ GULP_FILE_READ_ERROR
Definition kls_gulp.h:81
bool kstr_indexof(Kstr k, char c, int *idx)
Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first...
Definition koliseo.c:3450
const char * gulp_res_names[TOT_GULP_RES+1]
String array for representations of Gulp_Res.
Definition koliseo.c:3268
bool kstr_eq(Kstr left, Kstr right)
Checks if the two passed Kstr have exactly equal data.
Definition koliseo.c:3324
KLS_Region_List kls_rl_t_cons(Koliseo_Temp *t_kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2688
void * kls_push_zero_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1562
char * kls_strdup(Koliseo *kls, char *source)
Function to dupe a C string to a Koliseo, and return a pointer to the allocated string.
Definition koliseo.c:4052
void * kls_temp_pop(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3935
Koliseo_Temp * kls_temp_start(Koliseo *kls)
Starts a new savestate for the passed Koliseo pointer, by initialising its Koliseo_Temp pointer and r...
Definition koliseo.c:2346
KLS_Region_List kls_rl_cons(Koliseo *kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2587
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:2234
void print_temp_kls_2file(FILE *fp, const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to the passed FILE pointer.
Definition koliseo.c:2195
KLS_Region_List kls_rl_insord_p(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2944
char * kls_t_strdup(Koliseo_Temp *t_kls, char *source)
Function to dupe a C string to a Koliseo_Temp, and return a pointer to the allocated string.
Definition koliseo.c:4081
int kls_get_maxRegions_KLS_BASIC(Koliseo *kls)
Calcs the max number of possible KLS_PUSH ops when using KLS_BASIC reglist alloc backend.
Definition koliseo.c:378
KLS_Stats KLS_STATS_DEFAULT
Definition koliseo.c:72
void kls_log(Koliseo *kls, const char *tag, const char *format,...)
Logs a message to the log_fp FILE field of the passed Koliseo pointer, if its conf....
Definition koliseo.c:451
KLS_list_element kls_rl_head(KLS_Region_List l)
Definition koliseo.c:2569
ptrdiff_t kls_total_padding(Koliseo *kls)
Calc memory used as padding for the passed Koliseo.
Definition koliseo.c:3244
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2498
bool kls_rl_member(KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2847
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:295
char ** kls_strdup_arr(Koliseo *kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo, and return a pointer to the allocated array.
Definition koliseo.c:4065
bool kls_rl_isLess(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if the first one has a smaller size.
Definition koliseo.c:3084
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:2181
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:100
bool kls_rl_empty(KLS_Region_List l)
Definition koliseo.c:2560
Koliseo * kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koli...
Definition koliseo.c:714
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:368
void * kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3981
void * kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3867
int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp *t_kls)
Calcs the max number of possible KLS_PUSH_T ops when using KLS_BASIC reglist alloc backend.
Definition koliseo.c:413
Koliseo * kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, and an allocation function pointer.
Definition koliseo.c:605
KLS_Region_List kls_rl_diff(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3058
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:2288
KLS_Region_List kls_rl_insord(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2926
KLS_Region_List kls_rl_emptyList(void)
Definition koliseo.c:2555
void kls_rl_freeList(KLS_Region_List l)
Frees all values and nodes for passed Region list.
Definition koliseo.c:2784
Koliseo * kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func)
Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer.
Definition koliseo.c:665
char ** kls_t_strdup_arr(Koliseo_Temp *t_kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo_Temp, and return a pointer to the allocated array.
Definition koliseo.c:4094
void * kls_temp_push_zero_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1659
ptrdiff_t kls_regionSize(KLS_Region *r)
Return size of a passed KLS_Region.
Definition koliseo.c:3132
Koliseo * kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koli...
Definition koliseo.c:682
void * kls_push_zero_named(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1757
int kls_rl_length(KLS_Region_List l)
Definition koliseo.c:2860
void * kls_temp_push_zero_named(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char *name, char *desc)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1855
void kls_usageReport_toFile(Koliseo *kls, FILE *fp)
Prints an usage report for the passed Koliseo to the passed file.
Definition koliseo.c:3175
KLS_Region_List kls_rl_copy(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2896
KLS_Region_List kls_rl_reverse(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2882
void * kls_push_zero(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1321
ptrdiff_t kls_avg_regionSize(Koliseo *kls)
Return average region size in usage for the passed Koliseo.
Definition koliseo.c:3142
KLS_Region_List kls_rl_delete(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2909
bool kls_rl_isEqual(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if their size is equal.
Definition koliseo.c:3098
Koliseo * kls_new_traced_AR_KLS_alloc_handled(ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a succ...
Definition koliseo.c:733
Koliseo * kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:495
void * kls_pop(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:3830
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Definition koliseo.c:162
void * kls_temp_push_zero_typed(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
Takes a Koliseo_Temp, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
Definition koliseo.c:2051
KLS_Region_List kls_rl_tail(KLS_Region_List l)
Definition koliseo.c:2578
KLS_Region_List kls_rl_append(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2869
void kls_rl_showList_toFile(KLS_Region_List l, FILE *fp)
Definition koliseo.c:2803
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:46
const char * kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]
Definition koliseo.c:88
void KLS_ZEROCOUNT_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)
Used internally for handling zero-count in push calls when no user handler is provided.
Definition koliseo.c:204
Koliseo * kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer.
Definition koliseo.c:631
KLS_Region_List kls_rl_mergeList(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3007
KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:286
KLS_Region_List kls_rl_intersect(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:3037
void print_kls_2file(FILE *fp, const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to the passed FILE pointer.
Definition koliseo.c:2141
KLS_Conf kls_conf_init_handled(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, FILE *log_fp, const char *log_filepath, KLS_Err_Handlers err_handlers)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:228
void kls_rl_showList(KLS_Region_List l)
Definition koliseo.c:2842
double kls_usageShare(KLS_Region *r, Koliseo *kls)
Returns the ratio of memory used by the passed KLS_Region relative to the passed Koliseo as a double.
Definition koliseo.c:3112
ptrdiff_t kls_type_usage(int type, Koliseo *kls)
Calc memory used by the specific type of KLS_list_element.
Definition koliseo.c:3217
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:2268
const char * kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be)
Definition koliseo.c:115
Koliseo * kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func)
Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a succ...
Definition koliseo.c:776
void * kls_push_zero_typed(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char *name, char *desc)
Takes a Koliseo pointer, a KLS_Region_Type index, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1954
void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize)
Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
Definition koliseo.c:2246
void KLS_OOM_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)
Used internally for handling Out-Of-Memory in push calls when no user handler is provided.
Definition koliseo.c:142
void kls_usageReport(Koliseo *kls)
Print usage report for passed Koliseo to stdout.
Definition koliseo.c:3205
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:109
size_t len
Definition kls_gulp.h:29
const char * data
Definition kls_gulp.h:28