71 ramlog = ocs_malloc(ocs,
sizeof(*ramlog), OCS_M_ZERO | OCS_M_NOWAIT);
73 ocs_log_err(ocs,
"ocs_malloc ramlog failed\n");
77 ramlog->textbuf_count = buffer_count;
79 ramlog->textbufs = ocs_malloc(ocs,
sizeof(*ramlog->textbufs)*buffer_count,
80 OCS_M_ZERO | OCS_M_NOWAIT | OCS_M_NONUMA);
81 if (ramlog->textbufs == NULL) {
82 ocs_log_err(ocs,
"ocs_malloc textbufs failed\n");
87 for (i = 0; i < buffer_count; i ++) {
90 ocs_log_err(ocs,
"ocs_textbuf_alloc failed\n");
96 ramlog->cur_textbuf_idx = 0;
97 ramlog->textbuf_base = 1;
98 ramlog->cur_textbuf = &ramlog->textbufs[0];
99 ramlog->initialized = TRUE;
100 ocs_lock_init(ocs, &ramlog->lock,
"ramlog_lock[%d]",
ocs_instance(ocs));
120 if (ramlog != NULL) {
121 ocs_lock_free(&ramlog->lock);
122 if (ramlog->textbufs) {
123 for (i = 0; i < ramlog->textbuf_count; i ++) {
127 ocs_free(ocs, ramlog->textbufs, ramlog->textbuf_count*
sizeof(*ramlog->textbufs));
128 ramlog->textbufs = NULL;
130 ocs_free(ocs, ramlog,
sizeof(*ramlog));
148 ocs_ramlog_clear(ocs_t *ocs, ocs_ramlog_t *ramlog,
int clear_start_of_day,
int clear_recent)
153 for (i = ramlog->textbuf_base; i < ramlog->textbuf_count; i ++) {
156 ramlog->cur_textbuf_idx = 1;
158 if (clear_start_of_day && ramlog->textbuf_base) {
163 ramlog->textbuf_base = 0;
185 if (ocs == NULL || ocs->ramlog == NULL) {
211 if (ramlog == NULL || !ramlog->initialized) {
218 ocs_lock(&ramlog->lock);
221 ramlog->cur_textbuf = &ramlog->textbufs[ramlog->cur_textbuf_idx];
226 ocs_unlock(&ramlog->lock);
247 if (idx >= ramlog->textbuf_count) {
248 idx = ramlog->textbuf_base;
272 if ((ramlog == NULL) || (ramlog->textbufs == NULL)) {
281 if (ramlog->textbuf_base) {
282 rltextbuf = &ramlog->textbufs[0];
293 for (i = ramlog->textbuf_base; i < ramlog->textbuf_count; i ++) {
294 rltextbuf = &ramlog->textbufs[idx];
uint32_t ocs_instance(void *os)
Return instance index of an opaque ocs structure.
static uint32_t ocs_ramlog_next_idx(ocs_ramlog_t *ramlog, uint32_t idx)
Return next ramlog buffer index.
int32_t ocs_ramlog_printf(void *os, const char *fmt,...)
Append formatted printf data to a ramlog buffer.
int32_t ocs_textbuf_remaining(ocs_textbuf_t *textbuf)
int32_t ocs_textbuf_get_written(ocs_textbuf_t *textbuf)
uint8_t * ocs_textbuf_get_buffer(ocs_textbuf_t *textbuf)
int32_t ocs_ddump_ramlog(ocs_textbuf_t *textbuf, ocs_ramlog_t *ramlog)
Perform ramlog buffer driver dump.
void ocs_ddump_section(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
Generate driver dump section start data.
void ocs_textbuf_free(ocs_t *ocs, ocs_textbuf_t *textbuf)
int32_t ocs_ramlog_vprintf(ocs_ramlog_t *ramlog, const char *fmt, va_list ap)
Append formatted text to a ramlog using variable arguments.
void ocs_ramlog_free(ocs_t *ocs, ocs_ramlog_t *ramlog)
Free a ramlog buffer.
ocs_textbuf_t * cur_textbuf
const char const char va_list ap
void ocs_ddump_endsection(ocs_textbuf_t *textbuf, const char *name, uint32_t instance)
Generate driver dump section end data.
void ocs_textbuf_vprintf(ocs_textbuf_t *textbuf, const char *fmt, va_list ap)
void ocs_textbuf_buffer(ocs_textbuf_t *textbuf, uint8_t *buffer, uint32_t buffer_length)
void ocs_textbuf_reset(ocs_textbuf_t *textbuf)
int32_t ocs_textbuf_alloc(ocs_t *ocs, ocs_textbuf_t *textbuf, uint32_t length)
void ocs_ramlog_clear(ocs_t *ocs, ocs_ramlog_t *ramlog, int clear_start_of_day, int clear_recent)
Clear a ramlog buffer.
const char const char * fmt
ocs_ramlog_t * ocs_ramlog_init(ocs_t *ocs, uint32_t buffer_len, uint32_t buffer_count)
Allocate a ramlog buffer.