timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
timemory_c.c
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to
9// deal in the Software without restriction, including without limitation the
10// rights to use, copy, modify, merge, publish, distribute, sublicense, and
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23// IN THE SOFTWARE.
24
25#include "timemory/enum.h"
26#include "timemory/library.h"
27#include "timemory/timemory.h"
28
29#include <assert.h>
30#include <stdarg.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35#if defined(__cplusplus)
36extern "C"
37{
38#endif
39
40#if !defined(TIMEMORY_WINDOWS)
41 char* strdup(const char* s)
42 {
43 size_t slen = strlen(s);
44 char* result = malloc(slen + 1);
45 if(result == NULL)
46 {
47 return NULL;
48 }
49
50 memcpy(result, s, slen + 1);
51 return result;
52 }
53#endif
54
55 //==================================================================================//
56
57 void c_timemory_init(int argc, char** argv, timemory_settings _settings)
58 {
61 }
62
63 //==================================================================================//
64
66
67 //==================================================================================//
68
70
71 //==================================================================================//
72
73 void* c_timemory_create_auto_timer(const char* tag)
74 {
75 void* _ret = NULL;
78 return _ret;
79 }
80
81 //==================================================================================//
82
83 void* c_timemory_create_auto_tuple(const char* tag, ...)
84 {
86 return NULL;
87
88 const int max_size = (int) TIMEMORY_COMPONENTS_END;
89 int num_components = 0;
90 int* components = (int*) malloc(max_size * sizeof(int));
91 if(!components)
92 return NULL;
93 va_list args;
94 va_start(args, tag);
95 for(int i = 0; i < max_size; ++i)
96 {
97 int comp = va_arg(args, int);
98 if(comp >= TIMEMORY_COMPONENTS_END)
99 break;
100 ++num_components;
101 components[i] = comp;
102 }
103 va_end(args);
104
105 void* ptr = NULL;
106 if(num_components > 0)
107 ptr = cxx_timemory_create_auto_tuple(tag, num_components, components);
108 free(components);
109
110 return ptr;
111 }
112
113 //==================================================================================//
114
116 {
117 ctimer = cxx_timemory_delete_auto_timer(ctimer);
118 assert(ctimer == NULL);
119 }
120
121 //==================================================================================//
122
124 {
125 ctuple = cxx_timemory_delete_auto_tuple(ctuple);
126 assert(ctuple == NULL);
127 }
128
129 //==================================================================================//
130
131 const char* c_timemory_blank_label(const char* _extra)
132 {
133 return cxx_timemory_label(0, 0, "", "", _extra);
134 }
135
136 //==================================================================================//
137
138 const char* c_timemory_basic_label(const char* _func, const char* _extra)
139 {
140 return cxx_timemory_label(1, 0, _func, "", _extra);
141 }
142
143 //==================================================================================//
144
145 const char* c_timemory_label(const char* _func, const char* _file, int _line,
146 const char* _extra)
147 {
148 return cxx_timemory_label(2, _line, _func, _file, _extra);
149 }
150
151 //==================================================================================//
152
153#if defined(__cplusplus)
154}
155#endif
void cxx_timemory_init(int, char **, timemory_settings)
void * cxx_timemory_delete_auto_tuple(void *)
void * cxx_timemory_delete_auto_timer(void *)
int cxx_timemory_enabled(void)
void * cxx_timemory_create_auto_timer(const char *)
const char * cxx_timemory_label(int, int, const char *, const char *, const char *)
void * cxx_timemory_create_auto_tuple(const char *, int, const int *)
#define TIMEMORY_COMPONENTS_END
Definition: enum.h:155
void timemory_init_library(int argc, char **argv)
Initializes timemory. Not strictly necessary but highly recommended.
Definition: library.cpp:212
void timemory_finalize_library(void)
Finalizes timemory. Output will be generated. Any attempt to store data within timemory storage is un...
Definition: library.cpp:253
const hash_alias_ptr_t hash_value_t std::string *& _ret
Definition: definition.hpp:300
const auto & _file
Definition: definition.hpp:72
char ** argv
Definition: config.cpp:55
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255
components
Definition: settings.cpp:1700
char * strdup(const char *s)
Definition: timemory_c.c:41
void * c_timemory_create_auto_tuple(const char *tag,...)
Definition: timemory_c.c:83
int c_timemory_enabled(void)
Definition: timemory_c.c:69
void c_timemory_finalize(void)
Definition: timemory_c.c:65
const char * c_timemory_basic_label(const char *_func, const char *_extra)
Definition: timemory_c.c:138
const char * c_timemory_blank_label(const char *_extra)
Definition: timemory_c.c:131
void c_timemory_delete_auto_timer(void *ctimer)
Definition: timemory_c.c:115
void c_timemory_init(int argc, char **argv, timemory_settings _settings)
Definition: timemory_c.c:57
const char * c_timemory_label(const char *_func, const char *_file, int _line, const char *_extra)
Definition: timemory_c.c:145
void c_timemory_delete_auto_tuple(void *ctuple)
Definition: timemory_c.c:123
void * c_timemory_create_auto_timer(const char *tag)
Definition: timemory_c.c:73