Skip to content

Commit 1097000

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Improve documentation about our event buffer size configuration. (#25255)
1 parent d098fde commit 1097000

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

src/app/EventManagement.h

+40-16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@
3737
#include <lib/support/CHIPCounter.h>
3838
#include <messaging/ExchangeMgr.h>
3939

40+
/**
41+
* Events are stored in the LogStorageResources provided to
42+
* EventManagement::Init.
43+
*
44+
* A newly generated event will be placed in the lowest-priority (in practice
45+
* DEBUG) buffer, the one associated with the first LogStorageResource. If
46+
* there is no space in that buffer, space will be created by evicting the
47+
* oldest event currently in that buffer, until enough space is available.
48+
*
49+
* When an event is evicted from a buffer, there are two possibilities:
50+
*
51+
* 1) If the next LogStorageResource has a priority that is no higher than the
52+
* event's priority, the event will be moved to that LogStorageResource's
53+
* buffer. This may in turn require events to be evicted from that buffer.
54+
* 2) If the next LogStorageResource has a priority that is higher than the
55+
* event's priority, then the event is just dropped.
56+
*
57+
* This means that LogStorageResources at a given priority level are reserved
58+
* for events of that priority level or higher priority.
59+
*
60+
* As a simple example, assume there are only two priority levels, DEBUG and
61+
* CRITICAL, and two LogStorageResources with those priorities. In that case,
62+
* old CRITICAL events will not start getting dropped until both buffers are
63+
* full, while old DEBUG events will start getting dropped once the DEBUG
64+
* LogStorageResource buffer is full.
65+
*/
66+
4067
#define CHIP_CONFIG_EVENT_GLOBAL_PRIORITY PriorityLevel::Debug
4168

4269
namespace chip {
@@ -162,31 +189,28 @@ struct LogStorageResources
162189

163190
/**
164191
* @brief
165-
* A class for managing the in memory event logs.
166-
* Assume we have two importance levels. DEBUG and CRITICAL, for simplicity,
167-
* A new incoming event will always get logged in buffer with debug buffer no matter it is Debug or CRITICAL event.
168-
* In order for it to get logged, we need to free up space. So we look at the tail of the buffer.
169-
* If the tail of the buffer contains a DEBUG event, that will be dropped. If the tail of the buffer contains
170-
* a CRITICAL event, that event will be 'promoted' to the next level of buffers, where it will undergo the same procedure
171-
* The outcome of this management policy is that the critical buffer is dedicated to the critical events, and the
172-
* debug buffer is shared between critical and debug events.
192+
* A class for managing the in memory event logs. See documentation at the
193+
* top of the file describing the eviction policy for events when there is no
194+
* more space for new events.
173195
*/
174196

175197
class EventManagement
176198
{
177199
public:
178200
/**
179-
* @brief
180-
* Initialize the EventManagement with an array of LogStorageResources. The
181-
* array must provide a resource for each valid priority level, the elements
182-
* of the array must be in increasing numerical value of priority (and in
183-
* increasing priority); the first element in the array corresponds to the
184-
* resources allocated for least important events, and the last element
185-
* corresponds to the most critical events.
201+
* Initialize the EventManagement with an array of LogStorageResources and
202+
* an equal-length array of CircularEventBuffers that correspond to those
203+
* LogStorageResources. The array of LogStorageResources must provide a
204+
* resource for each valid priority level, the elements of the array must be
205+
* in increasing numerical value of priority (and in increasing priority);
206+
* the first element in the array corresponds to the resources allocated for
207+
* least important events, and the last element corresponds to the most
208+
* critical events.
186209
*
187210
* @param[in] apExchangeManager ExchangeManager to be used with this logging subsystem
188211
*
189-
* @param[in] aNumBuffers Number of elements in inLogStorageResources array
212+
* @param[in] aNumBuffers Number of elements in the apLogStorageResources
213+
* and apCircularEventBuffer arrays.
190214
*
191215
* @param[in] apCircularEventBuffer An array of CircularEventBuffer for each priority level.
192216
*

src/include/platform/CHIPDeviceConfig.h

+21-8
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,12 @@
952952
* @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE
953953
*
954954
* @brief
955-
* A size, in bytes, of the individual critical event logging buffer.
956-
* Note: the critical event buffer must exist.
955+
* A size, in bytes, of the buffer reserved for storing CRITICAL events and no
956+
* other events. CRITICAL events will never be evicted until this buffer is
957+
* full, so its size and the sizes of events determine how many of the last N
958+
* CRITICAL events are guaranteed to be available.
959+
*
960+
* Note: this number must be nonzero.
957961
*/
958962
#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE
959963
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE (1024)
@@ -967,9 +971,13 @@
967971
* @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
968972
*
969973
* @brief
970-
* A size, in bytes, of the individual info event logging buffer.
971-
* Note: set to 0 to disable info event buffer and all support
972-
* for the info level events.
974+
* A size, in bytes, of the buffer reserved for storing events at INFO
975+
* priority and higher. INFO-priority events will not be evicted until this
976+
* buffer is full (with INFO and CRITICAL events in it) and the oldest event
977+
* in the buffer is an INFO-priority event (which cannot be evicted into the
978+
* CRITICAL event buffer).
979+
*
980+
* Note: set to 0 to treat INFO events as effectively equivalent to DEBUG events.
973981
*/
974982
#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
975983
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE (512)
@@ -979,9 +987,14 @@
979987
* @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
980988
*
981989
* @brief
982-
* A size, in bytes, of the individual debug event logging buffer.
983-
* Note: set to 0 to disable debug event buffer and all support
984-
* for the debug level events.
990+
* A size, in bytes, of the buffer used for storing newly generated events,
991+
* and the only buffer in which DEBUG-priority events are allowed.
992+
* DEBUG-priority events will start getting evicted when this buffer is full
993+
* (with DEBUG, INFO, and CRITICAL events in it) and the oldest event in the
994+
* buffer is a DEBUG-priority event, which cannot be evicted into the INFO
995+
* event buffer.
996+
*
997+
* Note: set to 0 to disable storing DEBUG events.
985998
*/
986999
#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
9871000
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512)

0 commit comments

Comments
 (0)