| 1 | // SPDX-License-Identifier: BSD-2-Clausecxx . . $ `<file>/src/log.c`/ |
| 2 | /* |
| 3 | * Copyright (C) 2020-2025 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | #include <errno.h> |
| 7 | #include <inttypes.h> |
| 8 | #include <stdarg.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <time.h> |
| 13 | |
| 14 | #include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 15 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 16 | #include "stat.h"cxx . . $ `<file>/src/stat.h`/ |
| 17 | #include "thread.h"cxx . . $ `<file>/src/thread.h`/ |
| 18 | #include "utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 19 | |
| 20 | static struct statisticscxx . . $ statistics# global_statisticscxx . . $ global_statistics.[NUM_FRAME_TYPEScxx . . $ NUM_FRAME_TYPES.]; |
| 21 | static struct ring_buffercxx . . $ ring_buffer# *global_log_ring_buffercxx . . $ global_log_ring_buffer.; |
| 22 | static enum log_levelcxx . . $ log_level# current_log_levelcxx . . $ current_log_level.; |
| 23 | static FILEcxx . . $ FILE# *file_tracing_oncxx . . $ file_tracing_on.; |
| 24 | |
| 25 | int log_initcxx . . $ log_init(b126dc7c1de90089).(void) |
| 26 | { |
| 27 | global_log_ring_buffercxx . . $ global_log_ring_buffer. = ring_buffer_allocatecxx . . $ ring_buffer_allocate(a00a27d6b402ebff).(LOG_BUFFER_SIZEcxx . . $ `src/log.h:17:9`!); |
| 28 | |
| 29 | if (!global_log_ring_buffercxx . . $ global_log_ring_buffer.) |
| 30 | return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 31 | |
| 32 | /* Default */ |
| 33 | current_log_levelcxx . . $ current_log_level. = LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG.; |
| 34 | |
| 35 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(app_configcxx . . $ app_config..log_levelcxx . . $ application_config#log_level., "Debug")) |
| 36 | current_log_levelcxx . . $ current_log_level. = LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG.; |
| 37 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(app_configcxx . . $ app_config..log_levelcxx . . $ application_config#log_level., "Info")) |
| 38 | current_log_levelcxx . . $ current_log_level. = LOG_LEVEL_INFOcxx . . $ LOG_LEVEL_INFO.; |
| 39 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(app_configcxx . . $ app_config..log_levelcxx . . $ application_config#log_level., "Warning")) |
| 40 | current_log_levelcxx . . $ current_log_level. = LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING.; |
| 41 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(app_configcxx . . $ app_config..log_levelcxx . . $ application_config#log_level., "Error")) |
| 42 | current_log_levelcxx . . $ current_log_level. = LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR.; |
| 43 | |
| 44 | if (app_configcxx . . $ app_config..debug_stop_trace_on_errorcxx . . $ application_config#debug_stop_trace_on_error.) { |
| 45 | file_tracing_oncxx . . $ file_tracing_on. = fopencxx . . $ fopen(82ec0787cd37e0a3).("/sys/kernel/debug/tracing/tracing_on", "w"); |
| 46 | if (!file_tracing_oncxx . . $ file_tracing_on.) |
| 47 | return -errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | void log_freecxx . . $ log_free(49f6e7a06ebc5aa8).(void) |
| 54 | { |
| 55 | ring_buffer_freecxx . . $ ring_buffer_free(8f2cd700b00968de).(global_log_ring_buffercxx . . $ global_log_ring_buffer.); |
| 56 | |
| 57 | if (app_configcxx . . $ app_config..debug_stop_trace_on_errorcxx . . $ application_config#debug_stop_trace_on_error.) |
| 58 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(file_tracing_oncxx . . $ file_tracing_on.); |
| 59 | } |
| 60 | |
| 61 | static const char *log_level_to_stringcxx . . $ log_level_to_string(b9269a42575b6b84).(enum log_levelcxx . . $ log_level# level) |
| 62 | { |
| 63 | if (level == LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG.) |
| 64 | return "DEBUG"; |
| 65 | if (level == LOG_LEVEL_INFOcxx . . $ LOG_LEVEL_INFO.) |
| 66 | return "INFO"; |
| 67 | if (level == LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING.) |
| 68 | return "WARNING"; |
| 69 | if (level == LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR.) |
| 70 | return "ERROR"; |
| 71 | |
| 72 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 73 | } |
| 74 | |
| 75 | void log_messagecxx . . $ log_message(171546b8a219727a).(enum log_levelcxx . . $ log_level# level, const char *format, ...) |
| 76 | { |
| 77 | unsigned char buffer[4096]; |
| 78 | int written, len, ret; |
| 79 | struct timespeccxx . . $ timespec# time; |
| 80 | va_listcxx . . $ va_list# args; |
| 81 | char *p; |
| 82 | |
| 83 | /* Stop trace on error if desired. */ |
| 84 | if (level == LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR. && app_configcxx . . $ app_config..debug_stop_trace_on_errorcxx . . $ application_config#debug_stop_trace_on_error.) |
| 85 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(file_tracing_oncxx . . $ file_tracing_on., "0\n"); |
| 86 | |
| 87 | /* Log message only if log level fulfilled. */ |
| 88 | if (level > current_log_levelcxx . . $ current_log_level.) |
| 89 | return; |
| 90 | |
| 91 | /* Log each message with time stamps. */ |
| 92 | ret = clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., &time); |
| 93 | if (ret) |
| 94 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&time, '\0', sizeof(time)); |
| 95 | |
| 96 | len = sizeof(buffer) - 1; |
| 97 | p = (char *)buffer; |
| 98 | |
| 99 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(p, len, "[%8ld.%9ld]: [%s]: ", time.tv_seccxx . . $ timespec#tv_sec., time.tv_nseccxx . . $ timespec#tv_nsec., |
| 100 | log_level_to_stringcxx . . $ log_level_to_string(b9269a42575b6b84).(level)); |
| 101 | p += written; |
| 102 | len -= written; |
| 103 | |
| 104 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, format); |
| 105 | written += vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(p, len, format, args); |
| 106 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args); |
| 107 | |
| 108 | ring_buffer_addcxx . . $ ring_buffer_add(5f1d237704bb7e40).(global_log_ring_buffercxx . . $ global_log_ring_buffer., buffer, written); |
| 109 | } |
| 110 | |
| 111 | static void log_add_traffic_classcxx . . $ log_add_traffic_class(1f99a5bf22d7ae7b).(const char *name, enum stat_frame_typecxx . . $ stat_frame_type# frame_type, char **buffer, |
| 112 | size_t *length) |
| 113 | { |
| 114 | const struct statisticscxx . . $ statistics# *stat = &global_statisticscxx . . $ global_statistics.[frame_type]; |
| 115 | int written; |
| 116 | |
| 117 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).( |
| 118 | *buffer, *length, |
| 119 | "%sSent=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | %sReceived=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | %sRttMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 120 | " [us] | %sRttMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sRttAvg=%lf [us] | %sOnewayMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 121 | " [us] | %sOnewayMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sOnewayAvg=%lf [us] | ", |
| 122 | name, stat->frames_sentcxx . . $ statistics#frames_sent., name, stat->frames_receivedcxx . . $ statistics#frames_received., name, stat->round_trip_mincxx . . $ statistics#round_trip_min., |
| 123 | name, stat->round_trip_maxcxx . . $ statistics#round_trip_max., name, stat->round_trip_avgcxx . . $ statistics#round_trip_avg., name, stat->oneway_mincxx . . $ statistics#oneway_min., |
| 124 | name, stat->oneway_maxcxx . . $ statistics#oneway_max., name, stat->oneway_avgcxx . . $ statistics#oneway_avg.); |
| 125 | |
| 126 | *buffer += written; |
| 127 | *length -= written; |
| 128 | |
| 129 | if (app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled. && config_have_rx_timestampcxx . . $ config_have_rx_timestamp(c9857a73d68e59ba).() && |
| 130 | app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. && stat->proc_first_countcxx . . $ statistics#proc_first_count. > 0) { |
| 131 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 132 | "%sProcFirstMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sProcFirstMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 133 | " [us] | %sProcFirstAvg=%lf [us] | ", |
| 134 | name, stat->proc_first_mincxx . . $ statistics#proc_first_min., name, stat->proc_first_maxcxx . . $ statistics#proc_first_max., name, |
| 135 | stat->proc_first_avgcxx . . $ statistics#proc_first_avg.); |
| 136 | *buffer += written; |
| 137 | *length -= written; |
| 138 | } |
| 139 | |
| 140 | if (app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled. && config_have_rx_timestampcxx . . $ config_have_rx_timestamp(c9857a73d68e59ba).() && |
| 141 | app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].xdp_enabledcxx . . $ traffic_class_config#xdp_enabled. && stat->proc_batch_countcxx . . $ statistics#proc_batch_count. > 0) { |
| 142 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 143 | "%sProcBatchMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sProcBatchMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 144 | " [us] | %sProcBatchAvg=%lf [us] | ", |
| 145 | name, stat->proc_batch_mincxx . . $ statistics#proc_batch_min., name, stat->proc_batch_maxcxx . . $ statistics#proc_batch_max., name, |
| 146 | stat->proc_batch_avgcxx . . $ statistics#proc_batch_avg.); |
| 147 | *buffer += written; |
| 148 | *length -= written; |
| 149 | } |
| 150 | |
| 151 | if (config_have_rx_timestampcxx . . $ config_have_rx_timestamp(c9857a73d68e59ba).() && app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 152 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 153 | "%sRxMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sRxMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 154 | " [us] | %sRxAvg=%lf [us] | " |
| 155 | "%sRxHw2XdpMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sRxHw2XdpMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 156 | " [us] | %sRxHw2XdpAvg=%lf [us] | " |
| 157 | "%sRxXdp2AppMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sRxXdp2AppMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 158 | " [us] | %sRxXdp2AppAvg=%lf [us] | ", |
| 159 | name, stat->rx_mincxx . . $ statistics#rx_min., name, stat->rx_maxcxx . . $ statistics#rx_max., name, stat->rx_avgcxx . . $ statistics#rx_avg., name, |
| 160 | stat->rx_hw2xdp_mincxx . . $ statistics#rx_hw2xdp_min., name, stat->rx_hw2xdp_maxcxx . . $ statistics#rx_hw2xdp_max., name, |
| 161 | stat->rx_hw2xdp_avgcxx . . $ statistics#rx_hw2xdp_avg., name, stat->rx_xdp2app_mincxx . . $ statistics#rx_xdp2app_min., name, |
| 162 | stat->rx_xdp2app_maxcxx . . $ statistics#rx_xdp2app_max., name, stat->rx_xdp2app_avgcxx . . $ statistics#rx_xdp2app_avg.); |
| 163 | |
| 164 | *buffer += written; |
| 165 | *length -= written; |
| 166 | } |
| 167 | |
| 168 | if (app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].tx_hwtstamp_enabledcxx . . $ traffic_class_config#tx_hwtstamp_enabled. && |
| 169 | app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 170 | written = |
| 171 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 172 | "%sTxMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | %sTxMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 173 | " [us] | %sTxAvg=%lf [us] | %sTxHwTimestampMissing=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | ", |
| 174 | name, stat->tx_mincxx . . $ statistics#tx_min., name, stat->tx_maxcxx . . $ statistics#tx_max., name, stat->tx_avgcxx . . $ statistics#tx_avg., name, |
| 175 | stat->tx_hw_timestamp_missingcxx . . $ statistics#tx_hw_timestamp_missing.); |
| 176 | *buffer += written; |
| 177 | *length -= written; |
| 178 | } |
| 179 | |
| 180 | if (stat_frame_type_is_real_timecxx . . $ stat_frame_type_is_real_time(e6c3649086ff187f).(frame_type)) { |
| 181 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 182 | "%sRttOutliers=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | %sOnewayOutliers=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | ", |
| 183 | name, stat->round_trip_outlierscxx . . $ statistics#round_trip_outliers., name, stat->oneway_outlierscxx . . $ statistics#oneway_outliers.); |
| 184 | *buffer += written; |
| 185 | *length -= written; |
| 186 | } |
| 187 | |
| 188 | if (app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[frame_type].rx_workload_enabledcxx . . $ traffic_class_config#rx_workload_enabled.) { |
| 189 | written = snprintfcxx . . $ snprintf(ea502d73e74c754c).(*buffer, *length, |
| 190 | "%sRxWorkloadMin=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | " |
| 191 | "%sRxWorkloadMax=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " [us] | " |
| 192 | "%sRxWorkloadAvg=%lf [us] | " |
| 193 | "%sRxWorkloadOutliers=%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " | ", |
| 194 | name, stat->rx_workload_mincxx . . $ statistics#rx_workload_min., name, stat->rx_workload_maxcxx . . $ statistics#rx_workload_max., name, |
| 195 | stat->rx_workload_avgcxx . . $ statistics#rx_workload_avg., name, stat->rx_workload_outlierscxx . . $ statistics#rx_workload_outliers.); |
| 196 | |
| 197 | *buffer += written; |
| 198 | *length -= written; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | static void *log_thread_routinecxx . . $ log_thread_routine(9f162e79bfc6c74).(void *data) |
| 203 | { |
| 204 | struct log_thread_contextcxx . . $ log_thread_context# *log_context = data; |
| 205 | uint64_tcxx . . $ uint64_t# period = app_configcxx . . $ app_config..stats_collection_interval_nscxx . . $ application_config#stats_collection_interval_ns.; |
| 206 | struct timespeccxx . . $ timespec# time; |
| 207 | int ret; |
| 208 | |
| 209 | /* |
| 210 | * Write the content of the LogBuffer periodically to disk. This thread can run with low |
| 211 | * priority to not influence to Application Tasks that much. |
| 212 | */ |
| 213 | ret = clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., &time); |
| 214 | if (ret) { |
| 215 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Log: clock_gettime() failed: %s!", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 216 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 217 | } |
| 218 | |
| 219 | while (!log_context->stopcxx . . $ log_thread_context#stop.) { |
| 220 | size_t log_data_len, stat_message_length; |
| 221 | char stat_message[4096] = {}, *p; |
| 222 | int i; |
| 223 | |
| 224 | /* Wait until next period */ |
| 225 | increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(&time, period); |
| 226 | ret = clock_nanosleepcxx . . $ clock_nanosleep(99dc002056e22615).(app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id., TIMER_ABSTIMEcxx . . $ `<external>/89459239771508533/time.h:69:10`!, &time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 227 | if (ret) { |
| 228 | pthread_errorcxx . . $ pthread_error(66835f578de1bcb3).(ret, "clock_nanosleep() failed"); |
| 229 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 230 | } |
| 231 | |
| 232 | /* Get latest statistics data */ |
| 233 | stat_get_global_statscxx . . $ stat_get_global_stats(36543745c1651445).(global_statisticscxx . . $ global_statistics., sizeof(global_statisticscxx . . $ global_statistics.)); |
| 234 | |
| 235 | /* Log statistics once per logging period. */ |
| 236 | p = stat_message; |
| 237 | stat_message_length = sizeof(stat_message) - 1; |
| 238 | |
| 239 | for (i = 0; i < NUM_FRAME_TYPEScxx . . $ NUM_FRAME_TYPES.; i++) { |
| 240 | if (config_is_traffic_class_activecxx . . $ config_is_traffic_class_active(c5f7da30cbc0f4e9).(stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(i))) { |
| 241 | const char *name = |
| 242 | i == GENERICL2_FRAME_TYPEcxx . . $ GENERICL2_FRAME_TYPE. |
| 243 | ? app_configcxx . . $ app_config..classescxx . . $ application_config#classes.[GENERICL2_FRAME_TYPEcxx . . $ GENERICL2_FRAME_TYPE.].namecxx . . $ traffic_class_config#name. |
| 244 | : stat_frame_type_to_stringcxx . . $ stat_frame_type_to_string(413bfe925ee921da).(i); |
| 245 | |
| 246 | log_add_traffic_classcxx . . $ log_add_traffic_class(1f99a5bf22d7ae7b).(name, i, &p, &stat_message_length); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_INFOcxx . . $ LOG_LEVEL_INFO., "%s\n", stat_message); |
| 251 | |
| 252 | /* Fetch data */ |
| 253 | ring_buffer_fetchcxx . . $ ring_buffer_fetch(e8bf408057bf6314).(log_context->log_ring_buffercxx . . $ log_thread_context#log_ring_buffer., log_context->log_datacxx . . $ log_thread_context#log_data., |
| 254 | LOG_BUFFER_SIZEcxx . . $ `src/log.h:17:9`!, &log_data_len); |
| 255 | |
| 256 | /* Write down to disk */ |
| 257 | if (log_data_len > 0) { |
| 258 | fwritecxx . . $ fwrite(ab0609fa07c47d6e).(log_context->log_datacxx . . $ log_thread_context#log_data., sizeof(char), log_data_len, |
| 259 | log_context->file_handlecxx . . $ log_thread_context#file_handle.); |
| 260 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(log_context->file_handlecxx . . $ log_thread_context#file_handle.); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 265 | } |
| 266 | |
| 267 | struct log_thread_contextcxx . . $ log_thread_context# *log_thread_createcxx . . $ log_thread_create(3ed95045a9d7f639).(void) |
| 268 | { |
| 269 | struct log_thread_contextcxx . . $ log_thread_context# *log_context; |
| 270 | int ret; |
| 271 | |
| 272 | log_context = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*log_context)); |
| 273 | if (!log_context) |
| 274 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 275 | |
| 276 | log_context->log_datacxx . . $ log_thread_context#log_data. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(LOG_BUFFER_SIZEcxx . . $ `src/log.h:17:9`!, sizeof(char)); |
| 277 | if (!log_context->log_datacxx . . $ log_thread_context#log_data.) |
| 278 | goto err_log_data; |
| 279 | |
| 280 | log_context->log_ring_buffercxx . . $ log_thread_context#log_ring_buffer. = global_log_ring_buffercxx . . $ global_log_ring_buffer.; |
| 281 | |
| 282 | log_context->file_handlecxx . . $ log_thread_context#file_handle. = fopencxx . . $ fopen(82ec0787cd37e0a3).(app_configcxx . . $ app_config..log_filecxx . . $ application_config#log_file., "w+"); |
| 283 | if (!log_context->file_handlecxx . . $ log_thread_context#file_handle.) |
| 284 | goto err_fopen; |
| 285 | |
| 286 | ret = create_rt_threadcxx . . $ create_rt_thread(670ec5a211ade64c).(&log_context->log_task_idcxx . . $ log_thread_context#log_task_id., "Logger", app_configcxx . . $ app_config..log_thread_prioritycxx . . $ application_config#log_thread_priority., |
| 287 | app_configcxx . . $ app_config..log_thread_cpucxx . . $ application_config#log_thread_cpu., log_thread_routinecxx . . $ log_thread_routine(9f162e79bfc6c74)., log_context); |
| 288 | if (ret) |
| 289 | goto err_thread; |
| 290 | |
| 291 | return log_context; |
| 292 | |
| 293 | err_thread: |
| 294 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(log_context->file_handlecxx . . $ log_thread_context#file_handle.); |
| 295 | err_fopen: |
| 296 | freecxx . . $ free(5d22bdacc48458e8).(log_context->log_datacxx . . $ log_thread_context#log_data.); |
| 297 | err_log_data: |
| 298 | freecxx . . $ free(5d22bdacc48458e8).(log_context); |
| 299 | |
| 300 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 301 | } |
| 302 | |
| 303 | void log_thread_stopcxx . . $ log_thread_stop(5f50a2fc789db767).(struct log_thread_contextcxx . . $ log_thread_context# *thread_context) |
| 304 | { |
| 305 | if (!thread_context) |
| 306 | return; |
| 307 | |
| 308 | thread_context->stopcxx . . $ log_thread_context#stop. = 1; |
| 309 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->log_task_idcxx . . $ log_thread_context#log_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 310 | } |
| 311 | |
| 312 | void log_thread_freecxx . . $ log_thread_free(5f50a2fc789db767).(struct log_thread_contextcxx . . $ log_thread_context# *thread_context) |
| 313 | { |
| 314 | if (!thread_context) |
| 315 | return; |
| 316 | |
| 317 | freecxx . . $ free(5d22bdacc48458e8).(thread_context->log_datacxx . . $ log_thread_context#log_data.); |
| 318 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(thread_context->file_handlecxx . . $ log_thread_context#file_handle.); |
| 319 | freecxx . . $ free(5d22bdacc48458e8).(thread_context); |
| 320 | } |
| 321 | |
| 322 | void log_thread_wait_for_finishcxx . . $ log_thread_wait_for_finish(5f50a2fc789db767).(struct log_thread_contextcxx . . $ log_thread_context# *thread_context) |
| 323 | { |
| 324 | if (!thread_context) |
| 325 | return; |
| 326 | |
| 327 | pthread_joincxx . . $ pthread_join(269902cf949f12c5).(thread_context->log_task_idcxx . . $ log_thread_context#log_task_id., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 328 | } |