RTEMS 6.1-rc7
Loading...
Searching...
No Matches
recordclient.h
1/*
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (C) 2018, 2024 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/*
29 * This file must be compatible to general purpose POSIX system, e.g. Linux,
30 * FreeBSD. It may be used for utility programs.
31 */
32
33#ifndef _RTEMS_RECORDCLIENT_H
34#define _RTEMS_RECORDCLIENT_H
35
36#include "recorddata.h"
37
38#include <stdbool.h>
39#include <stddef.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
51#define RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT 32
52
53typedef enum {
54 RTEMS_RECORD_CLIENT_SUCCESS,
55 RTEMS_RECORD_CLIENT_ERROR_INVALID_MAGIC,
56 RTEMS_RECORD_CLIENT_ERROR_UNKNOWN_FORMAT,
57 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_VERSION,
58 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU,
59 RTEMS_RECORD_CLIENT_ERROR_UNSUPPORTED_CPU_MAX,
60 RTEMS_RECORD_CLIENT_ERROR_DOUBLE_CPU_MAX,
61 RTEMS_RECORD_CLIENT_ERROR_DOUBLE_PER_CPU_COUNT,
62 RTEMS_RECORD_CLIENT_ERROR_NO_CPU_MAX,
63 RTEMS_RECORD_CLIENT_ERROR_NO_MEMORY,
64 RTEMS_RECORD_CLIENT_ERROR_PER_CPU_ITEMS_OVERFLOW
65} rtems_record_client_status;
66
67typedef rtems_record_client_status ( *rtems_record_client_handler )(
68 uint64_t bt,
69 uint32_t cpu,
71 uint64_t data,
72 void *arg
73);
74
75typedef struct {
76 uint64_t uptime_bt;
77 uint32_t time_last;
78 uint64_t time_accumulated;
80
85#define RTEMS_RECORD_CLIENT_HOLD_BACK_REALLOCATION_LIMIT 0x100000
86
87typedef struct {
92
96 uint64_t last_bt;
97
101 uint32_t uptime_low;
102
107
112
119 rtems_record_item_64 *items;
120
125
131
133 uint64_t to_bt_scaler;
134 rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
135 uint32_t cpu;
136 uint32_t cpu_count;
137 uint32_t per_cpu_items;
138 union {
139 rtems_record_item_32 format_32;
140 rtems_record_item_64 format_64;
141 } item;
142 size_t todo;
143 void *pos;
144 rtems_record_client_status ( *consume )(
146 const void *,
147 size_t
148 );
149 rtems_record_client_handler handler;
150 void *handler_arg;
151 size_t data_size;
152 uint32_t header[ 2 ];
153 rtems_record_client_status status;
155
166rtems_record_client_status rtems_record_client_init(
168 rtems_record_client_handler handler,
169 void *arg
170);
171
179rtems_record_client_status rtems_record_client_run(
181 const void *buf,
182 size_t n
183);
184
195);
196
197static inline void rtems_record_client_set_handler(
199 rtems_record_client_handler handler
200)
201{
202 ctx->handler = handler;
203}
204
205static inline uint64_t rtems_record_client_bintime_to_nanoseconds(
206 uint64_t bt
207)
208{
209 uint64_t ns_per_sec;
210 uint64_t nanoseconds;
211
212 ns_per_sec = 1000000000ULL;
213 nanoseconds = ns_per_sec * ( (uint32_t) ( bt >> 32 ) );
214 nanoseconds += ( ns_per_sec * (uint32_t) bt ) >> 32;
215
216 return nanoseconds;
217}
218
219static inline void rtems_record_client_bintime_to_seconds_and_nanoseconds(
220 uint64_t bt,
221 uint32_t *seconds,
222 uint32_t *nanoseconds
223)
224{
225 uint64_t ns_per_sec;
226
227 ns_per_sec = 1000000000ULL;
228 *seconds = (uint32_t) ( bt >> 32 );
229 *nanoseconds = (uint32_t) ( ( ns_per_sec * (uint32_t) bt ) >> 32 );
230}
231
234#ifdef __cplusplus
235}
236#endif /* __cplusplus */
237
238#endif /* _RTEMS_RECORDCLIENT_H */
rtems_record_client_status rtems_record_client_init(rtems_record_client_context *ctx, rtems_record_client_handler handler, void *arg)
Initializes a record client.
Definition: record-client.c:634
void rtems_record_client_destroy(rtems_record_client_context *ctx)
Drains all internal buffers and frees the allocated resources.
Definition: record-client.c:704
rtems_record_event
The record events.
Definition: recorddata.h:90
rtems_record_client_status rtems_record_client_run(rtems_record_client_context *ctx, const void *buf, size_t n)
Runs the record client to consume new stream data.
Definition: record-client.c:657
Definition: recordclient.h:132
Definition: recordclient.h:87
bool uptime_low_valid
If true, then uptime low value is valid.
Definition: recordclient.h:106
uint64_t last_bt
The binary time of the last item.
Definition: recordclient.h:96
rtems_record_item_64 * items
Storage for hold back items.
Definition: recordclient.h:119
size_t item_capacity
The item capacity of the hold back storage.
Definition: recordclient.h:124
bool hold_back
If true, then hold back items.
Definition: recordclient.h:111
rtems_record_client_uptime uptime
Event time to uptime maintenance.
Definition: recordclient.h:91
size_t item_index
The index for the next hold back item.
Definition: recordclient.h:129
uint32_t uptime_low
Last RTEMS_RECORD_UPTIME_LOW data.
Definition: recordclient.h:101
Definition: recordclient.h:75
The 32-bit format record item.
Definition: recorddata.h:1200