mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-03 10:31:17 +08:00
record: Rework client
The ring buffer overflow handling is already performed by rtems_record_fetch().
This commit is contained in:
committed by
Chris Johns
parent
be764f7dec
commit
920f8d8897
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
|
||||
* Copyright (C) 2018, 2024 embedded brains GmbH & Co. KG
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -72,43 +72,28 @@ typedef rtems_record_client_status ( *rtems_record_client_handler )(
|
||||
void *arg
|
||||
);
|
||||
|
||||
typedef struct {
|
||||
uint64_t uptime_bt;
|
||||
uint32_t time_last;
|
||||
uint64_t time_accumulated;
|
||||
} rtems_record_client_uptime;
|
||||
|
||||
/**
|
||||
* @brief This constant defines the maximum capacity of the hold back item
|
||||
* storage in case a reallocation is necessary.
|
||||
*/
|
||||
#define RTEMS_RECORD_CLIENT_HOLD_BACK_REALLOCATION_LIMIT 0x100000
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief Event time to uptime maintenance.
|
||||
*/
|
||||
struct {
|
||||
uint64_t bt;
|
||||
uint32_t time_at_bt;
|
||||
uint32_t time_last;
|
||||
uint32_t time_accumulated;
|
||||
} uptime;
|
||||
rtems_record_client_uptime uptime;
|
||||
|
||||
/**
|
||||
* @brief The current or previous ring buffer tail.
|
||||
*
|
||||
* Indexed by the tail_head_index member.
|
||||
* @brief Last RTEMS_RECORD_UPTIME_LOW data.
|
||||
*/
|
||||
uint32_t tail[ 2 ];
|
||||
|
||||
/**
|
||||
* @brief The current or previous ring buffer head.
|
||||
*
|
||||
* Indexed by the tail_head_index member.
|
||||
*/
|
||||
uint32_t head[ 2 ];
|
||||
|
||||
/**
|
||||
* @brief The index of the tail and head members.
|
||||
*
|
||||
* This index is used to maintain the current and previous tail/head
|
||||
* positions to detect ring buffer overflows.
|
||||
*/
|
||||
size_t tail_head_index;
|
||||
|
||||
/**
|
||||
* @brief Count of lost items due to ring buffer overflows.
|
||||
*/
|
||||
uint32_t overflow;
|
||||
uint32_t uptime_low;
|
||||
|
||||
/**
|
||||
* @brief If true, then hold back items.
|
||||
@@ -123,6 +108,11 @@ typedef struct {
|
||||
*/
|
||||
rtems_record_item_64 *items;
|
||||
|
||||
/**
|
||||
* @brief The item capacity of the hold back storage.
|
||||
*/
|
||||
size_t item_capacity;
|
||||
|
||||
/**
|
||||
* @brief The index for the next hold back item.
|
||||
*/
|
||||
@@ -134,7 +124,7 @@ typedef struct rtems_record_client_context {
|
||||
rtems_record_client_per_cpu per_cpu[ RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT ];
|
||||
uint32_t cpu;
|
||||
uint32_t cpu_count;
|
||||
uint32_t count;
|
||||
uint32_t per_cpu_items;
|
||||
union {
|
||||
rtems_record_item_32 format_32;
|
||||
rtems_record_item_64 format_64;
|
||||
@@ -163,7 +153,7 @@ typedef struct rtems_record_client_context {
|
||||
* @param handler The handler is invoked for each received record item.
|
||||
* @param arg The handler argument.
|
||||
*/
|
||||
void rtems_record_client_init(
|
||||
rtems_record_client_status rtems_record_client_init(
|
||||
rtems_record_client_context *ctx,
|
||||
rtems_record_client_handler handler,
|
||||
void *arg
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,25 +53,25 @@ static rtems_record_client_status client_handler(
|
||||
void *arg
|
||||
)
|
||||
{
|
||||
uint32_t seconds;
|
||||
uint32_t nanoseconds;
|
||||
|
||||
(void) arg;
|
||||
|
||||
if ( bt != 0 ) {
|
||||
uint32_t seconds;
|
||||
uint32_t nanoseconds;
|
||||
|
||||
rtems_record_client_bintime_to_seconds_and_nanoseconds(
|
||||
bt,
|
||||
&seconds,
|
||||
&nanoseconds
|
||||
);
|
||||
|
||||
printf( "%" PRIu32 ".%09" PRIu32 ":", seconds, nanoseconds );
|
||||
} else {
|
||||
printf( "*:" );
|
||||
if (event == RTEMS_RECORD_USER_5) {
|
||||
return RTEMS_RECORD_CLIENT_SUCCESS;
|
||||
}
|
||||
|
||||
rtems_record_client_bintime_to_seconds_and_nanoseconds(
|
||||
bt,
|
||||
&seconds,
|
||||
&nanoseconds
|
||||
);
|
||||
printf(
|
||||
"%" PRIu32 ".%09" PRIu32 ":"
|
||||
"%" PRIu32 ":%s:%" PRIx64 "\n",
|
||||
seconds,
|
||||
nanoseconds,
|
||||
cpu,
|
||||
rtems_record_event_text( event ),
|
||||
data
|
||||
@@ -163,7 +163,17 @@ static void fetch(test_context *ctx)
|
||||
);
|
||||
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
|
||||
} while (fs == RTEMS_RECORD_FETCH_CONTINUE);
|
||||
}
|
||||
|
||||
static void overflow(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 512; ++i) {
|
||||
rtems_record_produce(RTEMS_RECORD_USER_5, 0);
|
||||
}
|
||||
|
||||
rtems_record_produce(RTEMS_RECORD_USER_6, 0);
|
||||
}
|
||||
|
||||
static void Init(rtems_task_argument arg)
|
||||
@@ -172,17 +182,25 @@ static void Init(rtems_task_argument arg)
|
||||
Record_Stream_header header;
|
||||
size_t size;
|
||||
rtems_record_client_status cs;
|
||||
rtems_interrupt_level level;
|
||||
|
||||
TEST_BEGIN();
|
||||
ctx = &test_instance;
|
||||
|
||||
generate_events();
|
||||
|
||||
rtems_record_client_init(&ctx->client, client_handler, NULL);
|
||||
cs = rtems_record_client_init(&ctx->client, client_handler, NULL);
|
||||
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
|
||||
size = _Record_Stream_header_initialize(&header);
|
||||
cs = rtems_record_client_run(&ctx->client, &header, size);
|
||||
rtems_test_assert(cs == RTEMS_RECORD_CLIENT_SUCCESS);
|
||||
fetch(ctx);
|
||||
|
||||
rtems_interrupt_local_disable(level);
|
||||
overflow();
|
||||
fetch(ctx);
|
||||
rtems_interrupt_local_enable(level);
|
||||
|
||||
rtems_record_client_destroy(&ctx->client);
|
||||
|
||||
generate_events();
|
||||
|
||||
Reference in New Issue
Block a user