koliseo 0.4.6
Loading...
Searching...
No Matches
koliseo.h
Go to the documentation of this file.
1// jgabaut @ github.com/jgabaut
2// SPDX-License-Identifier: GPL-3.0-only
3/*
4 Copyright (C) 2023-2024 jgabaut
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#ifndef KOLISEO_H_
20
21#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) //We need C11
22#define KOLISEO_H_
23
24#ifndef _WIN32
25#define _POSIX_C_SOURCE 200809L
26#endif
27
28#include <stdio.h>
29#include <stdint.h>
30#include <stddef.h>
31#include <stdlib.h>
32#include <stdarg.h>
33#include <assert.h>
34#include <string.h>
35#include <time.h>
36#include <stdbool.h>
37
38#ifdef KLS_DEBUG_CORE
39#include <time.h>
40
41/*
42#ifndef KOLISEO_HAS_LOCATE
43#define KOLISEO_HAS_LOCATE // Used for enabling caller location arguments for some APIs.
44#endif // KOLISEO_HAS_LOCATE
45*/
46
47#ifdef _WIN32
48#include <profileapi.h> //Used for QueryPerformanceFrequency(), QueryPerformanceCounter()
49#endif
50#endif //KLS_DEBUG_CORE
51
52#ifdef KOLISEO_HAS_LOCATE
53typedef struct Koliseo_Loc {
54 const char* file;
55 const int line;
56 const char* func;
57} Koliseo_Loc;
58
59#define KLS_HERE (Koliseo_Loc){ \
60 .file = __FILE__, \
61 .line = __LINE__, \
62 .func = __func__, \
63}
64
69#define KLS_Loc_Fmt "[%s:%i at %s():] "
70
75#define KLS_Loc_Arg(loc) (loc.file), (loc.line), (loc.func)
76#endif // KOLISEO_HAS_LOCATE
77
78#define KLS_MAJOR 0
79#define KLS_MINOR 4
80#define KLS_PATCH 6
82typedef void*(kls_alloc_func)(size_t);
84#define STRINGIFY_2(x) #x
85
86#define STRINGIFY(x) STRINGIFY_2(x)
87
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;
99
105extern const char* kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS];
106
112const char* kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be);
113#endif // KOLISEO_HAS_REGION
114
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.6";
130const char *string_koliseo_version(void);
131
135int int_koliseo_version(void);
136
137#define KLS_DEFAULT_SIZE (16*1024)
139#ifndef KLS_DEFAULT_ALIGNMENT
140#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *))
141#endif
142
147typedef enum KLS_Region_Type {
148 KLS_None = 0,
149 Temp_KLS_Header = 1,
150 KLS_Header = 2,
151} KLS_Region_Type;
152
157#define KLS_REGIONTYPE_MAX KLS_Header
158
163#define KLS_REGION_MAX_NAME_SIZE 15
168#define KLS_REGION_MAX_DESC_SIZE 20
169
170#ifdef KOLISEO_HAS_REGION
171
177typedef struct KLS_Region {
178 ptrdiff_t begin_offset;
179 ptrdiff_t end_offset;
180 ptrdiff_t size;
181 ptrdiff_t padding;
182 char name[KLS_REGION_MAX_NAME_SIZE + 1];
183 char desc[KLS_REGION_MAX_DESC_SIZE + 1];
184 int type;
185} KLS_Region;
186
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;
200
201typedef KLS_region_list_item *KLS_Region_List;
202#endif // KOLISEO_HAS_REGION
203
204struct Koliseo_Temp; //Forward declaration for Koliseo itself
205struct Koliseo; //Forward declaration for KLS_OOM_Handler
206
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);
209#else
210typedef void(KLS_OOM_Handler)(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
211#endif
212
213#ifndef KOLISEO_HAS_LOCATE
214typedef void(KLS_PTRDIFF_MAX_Handler)(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count);
215#else
216typedef void(KLS_PTRDIFF_MAX_Handler)(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
217#endif
218
219#ifndef KOLISEO_HAS_LOCATE
220void KLS_OOM_default_handler__(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count);
221#else
222void KLS_OOM_default_handler_dbg__(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
223#endif
224
225#ifndef KOLISEO_HAS_LOCATE
226void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count);
227#else
228void KLS_PTRDIFF_MAX_default_handler_dbg__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc);
229#endif
230
235typedef struct KLS_Err_Handlers {
236 KLS_OOM_Handler* OOM_handler;
237 KLS_PTRDIFF_MAX_Handler* PTRDIFF_MAX_handler;
238} KLS_Err_Handlers;
239
240#ifndef KOLISEO_HAS_LOCATE
241#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, }
242#else
243#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler_dbg__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, }
244#endif // KOLISEO_HAS_LOCATE
245
250typedef struct KLS_Conf {
251#ifdef KOLISEO_HAS_REGION
252 int kls_autoset_regions;
253 KLS_RegList_Alloc_Backend kls_reglist_alloc_backend;
254 ptrdiff_t kls_reglist_kls_size;
255 int kls_autoset_temp_regions;
256#endif // KOLISEO_HAS_REGION
257 int kls_collect_stats;
258 int kls_verbose_lvl;
259 FILE *kls_log_fp;
260 const char *kls_log_filepath;
261 int kls_block_while_has_temp;
262 KLS_Err_Handlers err_handlers;
263} KLS_Conf;
264
265KLS_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, FILE* log_fp, const char* log_filepath, KLS_Err_Handlers err_handlers);
266
267KLS_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, FILE* log_fp, const char* log_filepath);
268
269void kls_dbg_features(void);
270
275typedef struct KLS_Stats {
276 int tot_pushes;
277 int tot_temp_pushes;
278 int tot_pops;
279 int tot_temp_pops;
280 int tot_logcalls;
281 int tot_hiccups;
282#ifdef KOLISEO_HAS_REGION
283 ptrdiff_t avg_region_size;
284#endif
285#ifdef KLS_DEBUG_CORE
286 double worst_pushcall_time;
287#endif
288} KLS_Stats;
289
295extern KLS_Conf KLS_DEFAULT_CONF;
296
302extern KLS_Stats KLS_STATS_DEFAULT;
303
308#ifdef KOLISEO_HAS_REGION
309#ifndef _WIN32
310#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 }"
311#else
312#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 }"
313#endif
314#else
315
316#define KLS_Conf_Fmt "KLS_Conf { collect_stats: %i, verbose_lvl: %i, log_filepath: \"%s\", log_fp: %p }"
317#endif // KOLISEO_HAS_REGION
318
323#ifdef KOLISEO_HAS_REGION
324#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)
325#else
326#define KLS_Conf_Arg(conf) (conf.kls_collect_stats),(conf.kls_verbose_lvl),(conf.kls_log_filepath),(void*)(conf.kls_log_fp)
327#endif // KOLISEO_HAS_REGION
328
333#ifdef KOLISEO_HAS_REGION
334
335#ifndef _WIN32
336
337#ifdef KLS_DEBUG_CORE
338#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 }"
339#else
340#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 }"
341#endif // KLS_DEBUG_CORE
342
343#else
344
345#ifdef KLS_DEBUG_CORE
346#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 }"
347#else
348#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 }"
349#endif // KLS_DEBUG_CORE
350#endif // _WIN32
351
352#else
353
354#ifdef KLS_DEBUG_CORE
355#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 }"
356#else
357#define KLS_Stats_Fmt "KLS_Stats { tot_pushes: %i, tot_pops: %i, tot_temp_pushes: %i, tot_temp_pops: %i, tot_hiccups: %i }"
358#endif // KLS_DEBUG_CORE
359
360#endif // KOLISEO_HAS_REGION
361
366#ifdef KOLISEO_HAS_REGION
367#ifdef KLS_DEBUG_CORE
368#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)
369#else
370#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)
371#endif // KLS_DEBUG_CORE
372#else
373#ifdef KLS_DEBUG_CORE
374#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)
375#else
376#define KLS_Stats_Arg(stats) (stats.tot_pushes),(stats.tot_pops),(stats.tot_temp_pushes),(stats.tot_temp_pops),(stats.tot_hiccups)
377#endif // KLS_DEBUG_CORE
378#endif // KOLISEO_HAS_REGION
379
380#ifdef KOLISEO_HAS_REGION
387typedef struct KLS_Temp_Conf {
388 int kls_autoset_regions;
389 KLS_RegList_Alloc_Backend tkls_reglist_alloc_backend;
390 ptrdiff_t kls_reglist_kls_size;
391} KLS_Temp_Conf;
392#endif // KOLISEO_HAS_REGION
393
398#ifndef _WIN32
399#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %li}"
400#else
401#define KLS_Temp_Conf_Fmt "KLS_Temp_Conf {autoset_regions: %i, tkls_reglist_alloc_backend: %i, kls_reglist_kls_size: %lli}"
402#endif
403
408#define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size)
409
418typedef struct Koliseo {
419 char *data;
420 ptrdiff_t size;
421 ptrdiff_t offset;
422 ptrdiff_t prev_offset;
423#ifdef KOLISEO_HAS_REGION
424 KLS_Region_List regs;
425 struct Koliseo *reglist_kls;
426 int max_regions_kls_alloc_basic;
427#endif
428 int has_temp;
429 KLS_Conf conf;
430 KLS_Stats stats;
431 struct Koliseo_Temp *t_kls;
432} Koliseo;
433
438#ifndef _WIN32
439#define KLSFmt "KLS {begin: %p, curr: %p, size: %li, offset: %li, has_temp: %i}"
440#else
441#define KLSFmt "KLS {begin: %p, curr: %p, size: %lli, offset: %lli, has_temp: %i}"
442#endif
443
448#define KLS_Arg(kls) (void*)(kls),(void*)((kls)+(kls->offset)),(kls->size),(kls->offset),(kls->has_temp)
449
457typedef struct Koliseo_Temp {
458 Koliseo *kls;
459 ptrdiff_t offset;
460 ptrdiff_t prev_offset;
461#ifdef KOLISEO_HAS_REGION
462 KLS_Region_List t_regs;
463 Koliseo *reglist_kls;
464 int max_regions_kls_alloc_basic;
465 KLS_Temp_Conf conf;
466#endif
467} Koliseo_Temp;
468
469void kls_log(Koliseo * kls, const char *tag, const char *format, ...);
470ptrdiff_t kls_get_pos(const Koliseo * kls);
471
472#ifdef KOLISEO_HAS_REGION
473int kls_get_maxRegions_KLS_BASIC(Koliseo * kls);
474int kls_temp_get_maxRegions_KLS_BASIC(Koliseo_Temp * t_kls);
475#endif
476
477#ifndef KOLISEO_HAS_LOCATE
478Koliseo *kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
479#else
480Koliseo *kls_new_alloc_dbg(ptrdiff_t size, kls_alloc_func alloc_func, Koliseo_Loc loc);
481#define kls_new_alloc(size, alloc_func) kls_new_alloc_dbg((size), (alloc_func), KLS_HERE)
482#endif // KOLISEO_HAS_LOCATE
483
484#ifndef KLS_DEFAULT_ALLOCF
485#define KLS_DEFAULT_ALLOCF malloc
486#endif
487
488#define kls_new(size) kls_new_alloc((size), KLS_DEFAULT_ALLOCF)
489//bool kls_set_conf(Koliseo* kls, KLS_Conf conf);
490Koliseo *kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func);
491#define kls_new_conf(size, conf) kls_new_conf_alloc((size), (conf), KLS_DEFAULT_ALLOCF)
492Koliseo *kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
493Koliseo *kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func);
494#define kls_new_traced(size, output_path) kls_new_traced_alloc((size), (output_path), KLS_DEFAULT_ALLOCF)
495#define kls_new_traced_handled(size, output_path, err_handlers) kls_new_traced_alloc_handled((size), (output_path), KLS_DEFAULT_ALLOCF, (err_handlers))
496Koliseo *kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
497Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func);
498#define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF)
499#define kls_new_dbg_handled(size, err_handlers) kls_new_dbg_alloc_handled((size), KLS_DEFAULT_ALLOCF,(err_handlers))
500Koliseo *kls_new_traced_AR_KLS_alloc_handled(ptrdiff_t size, const char *output_path,
501 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers);
502Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path,
503 ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func);
504#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)
505#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))
506
507//void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
508
509#ifndef KOLISEO_HAS_LOCATE
510void *kls_push_zero(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
511 ptrdiff_t count);
512#else
513void *kls_push_zero_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
514 ptrdiff_t count, Koliseo_Loc loc);
515
516#define kls_push_zero(kls, size, align, count) kls_push_zero_dbg((kls), (size), (align), (count), KLS_HERE)
517#endif // KOLISEO_HAS_LOCATE
518
519#ifndef KOLISEO_HAS_LOCATE
520void *kls_push_zero_AR(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
521 ptrdiff_t count);
522#else
523void *kls_push_zero_AR_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
524 ptrdiff_t count, Koliseo_Loc loc);
525#define kls_push_zero_AR(kls, size, align, count) kls_push_zero_AR_dbg((kls), (size), (align), (count), KLS_HERE)
526#endif // KOLISEO_HAS_LOCATE
527
528#ifdef KOLISEO_HAS_REGION
529
530#ifndef KOLISEO_HAS_LOCATE
531void *kls_push_zero_named(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
532 ptrdiff_t count, char *name, char *desc);
533#else
534void *kls_push_zero_named_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
535 ptrdiff_t count, char *name, char *desc, Koliseo_Loc loc);
536#define kls_push_zero_named(kls, size, align, count, name, desc) kls_push_zero_named_dbg((kls), (size), (align), (count), (name), (desc), KLS_HERE)
537#endif // KOLISEO_HAS_LOCATE
538
539#ifndef KOLISEO_HAS_LOCATE
540void *kls_push_zero_typed(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
541 ptrdiff_t count, int type, char *name, char *desc);
542#else
543void *kls_push_zero_typed_dbg(Koliseo * kls, ptrdiff_t size, ptrdiff_t align,
544 ptrdiff_t count, int type, char *name, char *desc, Koliseo_Loc loc);
545#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)
546#endif // KOLISEO_HAS_LOCATE
547#endif // KOLISEO_HAS_REGION
548
552#define KLS_PUSH_ARR(kls, type, count) (type*)kls_push_zero_AR((kls), sizeof(type), _Alignof(type), (count))
553
558#define KLS_PUSH_STR(kls, cstr) KLS_PUSH_ARR((kls), char, strlen((cstr))+1)
559
563#ifdef KOLISEO_HAS_REGION
564#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named((kls), sizeof(type), _Alignof(type), (count), (name), (desc))
565#else
566#define KLS_PUSH_ARR_NAMED(kls, type, count, name, desc) KLS_PUSH_ARR((kls),type,(count))
567#endif // KOLISEO_HAS_REGION
568
572#define KLS_PUSH_STR_NAMED(kls, cstr, name, desc) KLS_PUSH_ARR_NAMED((kls), char, strlen((cstr)), (name), (desc))
573
577#ifdef KOLISEO_HAS_REGION
578#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))
579#else
580#define KLS_PUSH_ARR_TYPED(kls, type, count, region_type, name, desc) KLS_PUSH_ARR((kls),type,(count))
581#endif // KOLISEO_HAS_REGION
582
586#define KLS_PUSH_STR_TYPED(kls, cstr, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), char, strlen((cstr)), (region_type), (name), (desc))
587
591#define KLS_PUSH(kls, type) KLS_PUSH_ARR((kls), type, 1)
592
596#define KLS_PUSH_NAMED(kls, type, name, desc) KLS_PUSH_ARR_NAMED((kls), type, 1, (name), (desc))
597
602#define KLS_PUSH_EX(kls, type, name) KLS_PUSH_NAMED((kls), type, (name), STRINGIFY(type))
603
607#define KLS_PUSH_TYPED(kls, type, region_type, name, desc) KLS_PUSH_ARR_TYPED((kls), type, 1, (region_type), (name), (desc))
608
613#define KLS_PUSH_TYPED_EX(kls, type, region_type, name) KLS_PUSH_TYPED((kls), type, (region_type), (name), STRINGIFY(type))
614
615void kls_clear(Koliseo * kls);
616void kls_free(Koliseo * kls);
617void print_kls_2file(FILE * fp, const Koliseo * kls);
618void print_dbg_kls(const Koliseo * kls);
619void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize);
620
621#ifndef KOLISEO_HAS_LOCATE
622Koliseo_Temp *kls_temp_start(Koliseo * kls);
623#else
624Koliseo_Temp *kls_temp_start_dbg(Koliseo * kls, Koliseo_Loc loc);
625#define kls_temp_start(kls) kls_temp_start_dbg((kls), KLS_HERE)
626#endif // KOLISEO_HAS_LOCATE
627//bool kls_temp_set_conf(Koliseo_Temp* t_kls, KLS_Temp_Conf conf);
628void kls_temp_end(Koliseo_Temp * tmp_kls);
629
630#ifndef KOLISEO_HAS_LOCATE
631void *kls_temp_push_zero_AR(Koliseo_Temp * t_kls, ptrdiff_t size,
632 ptrdiff_t align, ptrdiff_t count);
633#else
634void *kls_temp_push_zero_AR_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
635 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc);
636#define kls_temp_push_zero_AR(t_kls, size, align, count) kls_temp_push_zero_AR_dbg((t_kls), (size), (align), (count), KLS_HERE)
637#endif // KOLISEO_HAS_LOCATE
638
639#ifdef KOLISEO_HAS_REGION
640#ifndef KOLISEO_HAS_LOCATE
641void *kls_temp_push_zero_named(Koliseo_Temp * t_kls, ptrdiff_t size,
642 ptrdiff_t align, ptrdiff_t count, char *name,
643 char *desc);
644#else
645void *kls_temp_push_zero_named_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
646 ptrdiff_t align, ptrdiff_t count, char *name,
647 char *desc, Koliseo_Loc loc);
648#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)
649#endif // KOLISEO_HAS_LOCATE
650
651#ifndef KOLISEO_HAS_LOCATE
652void *kls_temp_push_zero_typed(Koliseo_Temp * t_kls, ptrdiff_t size,
653 ptrdiff_t align, ptrdiff_t count, int type,
654 char *name, char *desc);
655#else
656void *kls_temp_push_zero_typed_dbg(Koliseo_Temp * t_kls, ptrdiff_t size,
657 ptrdiff_t align, ptrdiff_t count, int type,
658 char *name, char *desc, Koliseo_Loc loc);
659#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)
660#endif // KOLISEO_HAS_LOCATE
661#endif // KOLISEO_HAS_REGION
662void print_temp_kls_2file(FILE * fp, const Koliseo_Temp * t_kls);
663void print_dbg_temp_kls(const Koliseo_Temp * t_kls);
664
668#define KLS_PUSH_ARR_T(kls_temp, type, count) (type*)kls_temp_push_zero_AR((kls_temp), sizeof(type), _Alignof(type), (count))
669
674#define KLS_PUSH_STR_T(kls_temp, cstr) KLS_PUSH_ARR_T((kls_temp), char, strlen((cstr))+1)
675
679#ifdef KOLISEO_HAS_REGION
680#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))
681#else
682#define KLS_PUSH_ARR_T_NAMED(kls_temp, type, count, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
683#endif // KOLISEO_HAS_REGION
684
688#define KLS_PUSH_STR_T_NAMED(kls_temp, cstr, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), char, strlen((cstr)), (name), (desc))
689
693#ifdef KOLISEO_HAS_REGION
694#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))
695#else
696#define KLS_PUSH_ARR_T_TYPED(kls_temp, type, count, region_type, name, desc) KLS_PUSH_ARR_T((kls_temp),type,(count))
697#endif // KOLISEO_HAS_REGION
698
702#define KLS_PUSH_STR_T_TYPED(kls_temp, cstr, region_type, name, desc) KLS_PUSH_ARR_T_TYPED((kls_temp), char, strlen((cstr)), (region_type), (name), (desc))
703
707#define KLS_PUSH_T(kls_temp, type) KLS_PUSH_ARR_T((kls_temp), type, 1)
708
712#define KLS_PUSH_T_NAMED(kls_temp, type, name, desc) KLS_PUSH_ARR_T_NAMED((kls_temp), type, 1, (name), (desc))
713
718#define KLS_PUSH_T_EX(kls_temp, type, name) KLS_PUSH_T_NAMED((kls_temp), type, (name), STRINGIFY(type))
719
723#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))
724
729#define KLS_PUSH_T_TYPED_EX(kls_temp, type, region_type, name) KLS_PUSH_T_TYPED((kls_temp), type, (region_type), (name), STRINFIGY(type))
730
731#ifdef KOLISEO_HAS_REGION
732
733KLS_Region_List kls_rl_emptyList(void);
734#define KLS_RL_GETLIST() kls_rl_emptyList()
735bool kls_rl_empty(KLS_Region_List);
736KLS_list_element kls_rl_head(KLS_Region_List);
737KLS_Region_List kls_rl_tail(KLS_Region_List);
738KLS_Region_List kls_rl_cons(Koliseo *, KLS_list_element, KLS_Region_List);
739#ifdef KOLISEO_HAS_EXPER
740KLS_region_list_item* kls_rl_list_pop(Koliseo *kls);
741#endif // KOLISEO_HAS_EXPER
742KLS_Region_List kls_rl_t_cons(Koliseo_Temp *, KLS_list_element, KLS_Region_List);
743#ifdef KOLISEO_HAS_EXPER
744KLS_region_list_item* kls_rl_t_list_pop(Koliseo_Temp *t_kls);
745#endif // KOLISEO_HAS_EXPER
746
747void kls_rl_freeList(KLS_Region_List);
748#define KLS_RL_FREELIST(kls_list) kls_rl_freeList(kls_list)
749void kls_rl_showList(KLS_Region_List);
750#define kls_showList(list) kls_rl_showList((list))
751void kls_rl_showList_toFile(KLS_Region_List, FILE * fp);
752#define kls_showList_toFile(list, fp) kls_rl_showList_toFile((list), (fp))
753#define KLS_RL_ECHOLIST(kls_list) kls_rl_showList(kls_list)
754#define KLS_RL_PRINTLIST(kls_list,file) kls_rl_showList_toFile(kls_list,file)
755bool kls_rl_member(KLS_list_element, KLS_Region_List);
756int kls_rl_length(KLS_Region_List);
757KLS_Region_List kls_rl_append(Koliseo *, KLS_Region_List, KLS_Region_List);
758KLS_Region_List kls_rl_reverse(Koliseo *, KLS_Region_List);
759KLS_Region_List kls_rl_copy(Koliseo *, KLS_Region_List);
760KLS_Region_List kls_rl_delete(Koliseo *, KLS_list_element, KLS_Region_List);
761
762KLS_Region_List kls_rl_insord(Koliseo *, KLS_list_element, KLS_Region_List);
763#define KLS_RL_PUSHLIST(kls,reg,kls_list) kls_rl_insord(kls,reg,kls_list)
764KLS_Region_List kls_rl_insord_p(Koliseo *, KLS_list_element, KLS_Region_List);
765#define KLS_RL_PUSHLIST_P(kls,reg,kls_list) kls_rl_insord_p(kls,reg,kls_list)
766KLS_Region_List kls_rl_mergeList(Koliseo *, KLS_Region_List, KLS_Region_List);
767KLS_Region_List kls_rl_intersect(Koliseo *, KLS_Region_List, KLS_Region_List);
768KLS_Region_List kls_rl_diff(Koliseo *, KLS_Region_List, KLS_Region_List);
769
770#define KLS_RL_DIFF(kls,kls_list1,kls_list2) kls_rl_diff(kls,kls_list1,kls_list2)
771bool kls_rl_isLess(KLS_list_element, KLS_list_element);
772bool kls_rl_isEqual(KLS_list_element, KLS_list_element);
773double kls_usageShare(KLS_list_element, Koliseo *);
774ptrdiff_t kls_regionSize(KLS_list_element);
775ptrdiff_t kls_avg_regionSize(Koliseo *);
776void kls_usageReport_toFile(Koliseo *, FILE *);
777void kls_usageReport(Koliseo *);
778ptrdiff_t kls_type_usage(int, Koliseo *);
779
780#endif // KOLISEO_HAS_REGION
781
782#ifdef KOLISEO_HAS_GULP
784#ifndef KOLISEO_GULP_H_
785#define KOLISEO_GULP_H_
786
787#include "ctype.h" // Needed for isspace()...
788
789typedef struct Kstr {
790 const char* data;
791 size_t len;
792} Kstr;
793
794Kstr kstr_new(const char* str, size_t len);
795Kstr kstr_from_c_lit(const char* c_lit);
796bool kstr_eq(Kstr left, Kstr right);
797bool kstr_eq_ignorecase(Kstr left, Kstr right);
798Kstr kstr_cut_l(Kstr *k, size_t n);
799Kstr kstr_cut_r(Kstr *k, size_t n);
800Kstr kstr_trim_left(Kstr kstr);
801Kstr kstr_trim_right(Kstr kstr);
802Kstr kstr_trim(Kstr kstr);
803bool kstr_indexof(Kstr k, char c, int* idx);
804Kstr kstr_token(Kstr* k, char delim);
805bool kstr_try_token(Kstr* k, char delim, Kstr* part);
806Kstr kstr_token_kstr(Kstr* k, Kstr delim);
807
808#define KSTR(c_lit) kstr_new(c_lit, sizeof(c_lit) - 1)
809#define KSTR_NULL kstr_new(NULL, 0)
810
814#define Kstr_Fmt "%.*s"
818#define Kstr_Arg(kstr) (int) (kstr.len), (kstr.data)
819
827#define ONEGB_DEC_INT 1073741824
828
833#define GULP_MAX_FILE_SIZE ONEGB_DEC_INT
834
839typedef enum Gulp_Res {
840 GULP_FILE_OK=0,
841 GULP_FILE_NOT_EXIST,
842 GULP_FILE_TOO_LARGE,
843 GULP_FILE_READ_ERROR,
844 GULP_FILE_CONTAINS_NULLCHAR,
845 GULP_FILE_KLS_NULL,
846 TOT_GULP_RES
847} Gulp_Res;
848
852#define Gulp_Res_Fmt "%s"
856#define Gulp_Res_Arg(gr) (string_from_Gulp_Res((gr)))
857
862extern const char* gulp_res_names[TOT_GULP_RES+1];
863const char* string_from_Gulp_Res(Gulp_Res g);
864
865//static char * kls_read_file(Koliseo* kls, const char * f_name, Gulp_Res * err, size_t * f_size, ...);
866char * kls_gulp_file_sized(Koliseo* kls, const char * filepath, Gulp_Res * err, size_t max_size);
867char * try_kls_gulp_file(Koliseo* kls, const char * filepath, size_t max_size);
868#define KLS_GULP_FILE(kls, filepath) try_kls_gulp_file((kls),(filepath), GULP_MAX_FILE_SIZE)
869//Kstr * kls_read_file_to_kstr(Koliseo* kls, const char * f_name, Gulp_Res * err, size_t * f_size, ...);
870Kstr * kls_gulp_file_sized_to_kstr(Koliseo* kls, const char * filepath, Gulp_Res * err, size_t max_size, bool allow_nullchar);
871Kstr * try_kls_gulp_file_to_kstr(Koliseo* kls, const char * filepath, size_t max_size, bool allow_nullchar);
872#define KLS_GULP_FILE_KSTR(kls, filepath) try_kls_gulp_file_to_kstr((kls),(filepath), GULP_MAX_FILE_SIZE, false)
873
874#endif //KOLISEO_GULP_H_
875
876#endif //KOLISEO_HAS_GULP
877
878#ifdef KOLISEO_HAS_EXPER
879
880void *kls_pop(Koliseo * kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
881void *kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
882
887#define KLS_POP_ARR(kls, type, count) (type*)kls_pop_AR((kls), sizeof(type), _Alignof(type), (count))
888
893#define KLS_POP_STR(kls, cstr) KLS_POP_ARR((kls), char, strlen((cstr)))
894
899#define KLS_POP(kls, type) KLS_POP_ARR((kls), type, 1)
900
901void *kls_temp_pop(Koliseo_Temp * t_kls, ptrdiff_t size, ptrdiff_t align,
902 ptrdiff_t count);
903void *kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
904
909#define KLS_POP_ARR_T(kls_temp, type, count) (type*)kls_temp_pop_AR((kls_temp), sizeof(type), _Alignof(type), (count))
910
915#define KLS_POP_STR_T(kls_temp, cstr) KLS_POP_ARR_T((kls_temp), char, strlen((cstr)))
916
921#define KLS_POP_T(kls_temp, type) KLS_POP_ARR_T((kls_temp), type, 1)
922
923char* kls_strdup(Koliseo* kls, char* source);
924char** kls_strdup_arr(Koliseo* kls, size_t count, char** source);
925
933#define KLS__STRCPY(dest, source) do {\
934 strcpy((dest), (source));\
935} while (0)
936
937/*
938 * Macro to dupe a C string to a passed Koliseo, returns a pointer to the allocated string.
939 * Unsafe, do not use.
940 * @see kls_strdup()
941 */
942#define KLS_STRDUP(kls, source) kls_strdup((kls), (source))
943
944char* kls_t_strdup(Koliseo_Temp* t_kls, char* source);
945char** kls_t_strdup_arr(Koliseo_Temp* t_kls, size_t count, char** source);
946
947/*
948 * Macro to dupe a C string to a passed Koliseo_Temp, returns a pointer to the allocated string.
949 * Unsafe, do not use.
950 * @see kls_t_strdup()
951 */
952#define KLS_STRDUP_T(t_kls, source) kls_t_strdup((t_kls), (source))
953
954#endif // KOLISEO_HAS_EXPER
955
956#else
957#error "This code requires C11 or later.\n _Alignof() is not available"
958#endif // __STDC_VERSION__ && __STDC_VERSION__ >= 201112L //We need C11
959
960#endif //KOLISEO_H_
KLS_Region_List kls_rl_t_cons(Koliseo_Temp *t_kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2461
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:1335
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:3802
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:3685
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:2119
KLS_Region_List kls_rl_cons(Koliseo *kls, KLS_list_element e, KLS_Region_List l)
Definition koliseo.c:2360
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:2007
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:1968
KLS_Region_List kls_rl_insord_p(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2717
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:3831
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:332
const char * string_from_Gulp_Res(Gulp_Res g)
Return a constant string for the passed Gulp_Res.
Definition koliseo.c:3035
KLS_Stats KLS_STATS_DEFAULT
Definition koliseo.c:66
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:405
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:3513
KLS_list_element kls_rl_head(KLS_Region_List l)
Definition koliseo.c:2342
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2271
bool kls_rl_member(KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2620
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:249
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:3815
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:2857
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1954
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:3226
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:94
Kstr kstr_trim_left(Kstr kstr)
Returns a new Kstr after removing heading spaces from the passed one.
Definition koliseo.c:3155
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, 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:193
bool kls_rl_empty(KLS_Region_List l)
Definition koliseo.c:2333
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:668
bool kstr_eq_ignorecase(Kstr left, Kstr right)
Checks if the two passed Kstr have equal data, ignoring case.
Definition koliseo.c:3093
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:3373
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:322
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:3731
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:3617
Kstr kstr_trim_right(Kstr kstr)
Returns a new Kstr after removing trailing spaces from the passed one.
Definition koliseo.c:3170
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:367
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:3555
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:3414
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:559
KLS_Region_List kls_rl_diff(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2831
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:2061
KLS_Region_List kls_rl_insord(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2699
KLS_Region_List kls_rl_emptyList(void)
Definition koliseo.c:2328
Kstr kstr_cut_r(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the right.
Definition koliseo.c:3138
void kls_rl_freeList(KLS_Region_List l)
Frees all values and nodes for passed Region list.
Definition koliseo.c:2557
Kstr kstr_from_c_lit(const char *c_lit)
Returns a new Kstr from the passed null-terminated string.
Definition koliseo.c:3062
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:619
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:3844
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:1432
ptrdiff_t kls_regionSize(KLS_Region *r)
Return size of a passed KLS_Region.
Definition koliseo.c:2905
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:636
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:1530
int kls_rl_length(KLS_Region_List l)
Definition koliseo.c:2633
Kstr kstr_cut_l(Kstr *k, size_t n)
Cuts the passed Kstr by up to n chars, from the left.
Definition koliseo.c:3119
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:1628
void kls_usageReport_toFile(Koliseo *kls, FILE *fp)
Prints an usage report for the passed Koliseo to the passed file.
Definition koliseo.c:2948
KLS_Region_List kls_rl_copy(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2669
KLS_Region_List kls_rl_reverse(Koliseo *kls, KLS_Region_List l)
Definition koliseo.c:2655
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:1095
ptrdiff_t kls_avg_regionSize(Koliseo *kls)
Return average region size in usage for the passed Koliseo.
Definition koliseo.c:2915
KLS_Region_List kls_rl_delete(Koliseo *kls, KLS_list_element el, KLS_Region_List l)
Definition koliseo.c:2682
bool kls_rl_isEqual(KLS_Region *r1, KLS_Region *r2)
Compares two regions and returns true if their size is equal.
Definition koliseo.c:2871
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:3254
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:687
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:449
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:3580
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Definition koliseo.c:156
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:1824
KLS_Region_List kls_rl_tail(KLS_Region_List l)
Definition koliseo.c:2351
KLS_Region_List kls_rl_append(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2642
void kls_rl_showList_toFile(KLS_Region_List l, FILE *fp)
Definition koliseo.c:2576
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:43
const char * kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]
Definition koliseo.c:82
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:585
KLS_Region_List kls_rl_mergeList(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2780
Kstr kstr_trim(Kstr kstr)
Returns a new Kstr after removing heading and trailing spaces from the passed one.
Definition koliseo.c:3187
KLS_Region_List kls_rl_intersect(Koliseo *kls, KLS_Region_List l1, KLS_Region_List l2)
Definition koliseo.c:2810
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:1914
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, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:240
void kls_rl_showList(KLS_Region_List l)
Definition koliseo.c:2615
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:2885
ptrdiff_t kls_type_usage(int type, Koliseo *kls)
Calc memory used by the specific type of KLS_list_element.
Definition koliseo.c:2990
Kstr kstr_token_kstr(Kstr *k, Kstr delim)
Definition koliseo.c:3274
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:2041
const char * kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be)
Definition koliseo.c:109
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:730
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:1727
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:2019
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:136
void kls_usageReport(Koliseo *kls)
Print usage report for passed Koliseo to stdout.
Definition koliseo.c:2978
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:103
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:3200
const char * gulp_res_names[TOT_GULP_RES+1]
Contains the constant string representation of Gulp_Res values.
Definition koliseo.c:3018
bool kstr_eq(Kstr left, Kstr right)
Checks if the two passed Kstr have exactly equal data.
Definition koliseo.c:3074
Kstr kstr_new(const char *data, size_t len)
Returns a new Kstr with the passed args set.
Definition koliseo.c:3048