openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

evlog.c (2336B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        evlog.c
      8  * Purpose:
      9  * Requires:    
     10  */
     11 
     12 #include <shared/evlog.h>
     13 #include <appl/diag/evlog.h>
     14 #include <sal/core/libc.h>
     15 #include <shared/alloc.h>
     16 
     17 #include <bcm/error.h>
     18 
     19 #if defined(INCLUDE_SHARED_EVLOG)
     20 
     21 #define EV_ALLOC(ev, targ, size) do {                                   \
     22         targ = sal_alloc(size, "evlog");                                \
     23         if ((targ) == NULL) {                                           \
     24             diag_evlog_destroy(ev);                                     \
     25             return NULL;                                                \
     26         }                                                               \
     27         sal_memset(targ, 0, size);                                      \
     28     } while (0)
     29 
     30 shared_evlog_t *
     31 diag_evlog_create(int max_args, int max_entries)
     32 {
     33     shared_evlog_t *ev = NULL;
     34 
     35     EV_ALLOC(ev, ev, sizeof(*ev));
     36     EV_ALLOC(ev, ev->ev_strs, (sizeof(char *) * max_entries));
     37     EV_ALLOC(ev, ev->ev_args, (sizeof(int) * max_args * max_entries));
     38     EV_ALLOC(ev, ev->ev_ts, (sizeof(sal_usecs_t) * max_entries));
     39     EV_ALLOC(ev, ev->ev_tid, (sizeof(sal_thread_t) * max_entries));
     40     EV_ALLOC(ev, ev->ev_flags, (sizeof(uint32) * max_entries));
     41     ev->max_entries = max_entries;
     42     ev->max_args = max_args;
     43 
     44     return ev;
     45 }
     46 #undef EV_ALLOC
     47 
     48 #define EV_FREE(targ) if ((targ) != NULL) sal_free(targ)
     49 
     50 void
     51 diag_evlog_destroy(shared_evlog_t *ev)
     52 {
     53     if (ev != NULL) {
     54         EV_FREE(ev->ev_strs);
     55         EV_FREE(ev->ev_args);
     56         EV_FREE(ev->ev_ts);
     57         EV_FREE(ev->ev_tid);
     58         EV_FREE(ev->ev_flags);
     59 
     60         sal_free(ev);
     61     }
     62 }
     63 #undef EV_FREE
     64 
     65 
     66 /* To do:  Implement a reasonable "dump" function */
     67 int
     68 diag_evlog_dump(shared_evlog_t *ev, int count, int oldest)
     69 {
     70     /*
     71      * If count == 0, dump all entries in log
     72      * If count > 0, dump that many entries moving forward in time.
     73      * If count < 0, dump that many entries moving backward in time.
     74      *
     75      * If oldest is true, dump earliest entries.
     76      * Otherwise dump most recent entries.
     77      */
     78 
     79     return BCM_E_UNAVAIL;
     80 }
     81 
     82 #endif  /* INCLUDE_SHARED_EVLOG */