Motr  M0
iem.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2019-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_M0D
24 
25 #include "motr/iem.h"
26 #include "lib/trace.h"
27 
28 // For documentation links, please refer to this file :
29 // doc/motr-design-doc-list.rst
30 // Slide 4
31 const char M0_MOTR_IEM_SOURCE_ID = 'S';
32 
33 // Slide 12
35 
36 const char *m0_motr_iem_severity = "TAXEWNCIDB";
37 
45  uint64_t ir_niems;
46  uint64_t ir_total;
47 };
48 
50 
51 enum {
53  INTERVAL = 60,
55  THRESHOLD = 10
56 };
57 
58 void m0_iem(const char* file, const char* function, int line,
59  const enum m0_motr_iem_severity sev_id,
60  const enum m0_motr_iem_module mod_id,
61  const enum m0_motr_iem_event evt_id,
62  const char *msg, ...)
63 {
64  char description[512] = {0x0};
65  va_list aptr;
66 
67  M0_PRE(IS_IN_ARRAY(evt_id, iem_re));
68 
69  iem_re[evt_id].ir_total++;
70  /* Simple throttling scheme. */
71  if (m0_time_is_in_past(iem_re[evt_id].ir_stamp)) {
73  M0_MKTIME(INTERVAL, 0));
74  iem_re[evt_id].ir_niems = 0;
75  }
76 
77  if (msg != NULL && msg[0] != 0) {
78  va_start(aptr, msg);
79  vsnprintf(description, sizeof(description)-1, msg, aptr);
80  va_end(aptr);
81  }
82  if (mod_id == M0_MOTR_IEM_MODULE_IO &&
83  evt_id == M0_MOTR_IEM_EVENT_MD_ERROR) {
84  if (++iem_re[evt_id].ir_niems < THRESHOLD)
85  m0_console_printf("IEC: %c%c%03x%03x%04x: "
86  "IO error (%" PRIu64 "): "
87  "%s\n",
88  m0_motr_iem_severity[sev_id],
91  evt_id, iem_re[evt_id].ir_total,
92  description);
93  } else
94  m0_console_printf("IEC: %c%c%03x%03x%04x: %s\n",
95  m0_motr_iem_severity[sev_id],
98  mod_id, evt_id, description);
99 
101 
102  /* Do not throttle trace messages. */
103  if (mod_id == M0_MOTR_IEM_MODULE_IO &&
104  evt_id == M0_MOTR_IEM_EVENT_MD_ERROR)
105  M0_LOG(M0_INFO, "IEC: %c%c%3x%3x%4x: "
106  "IO error (%" PRIx64 "): %s",
107  m0_motr_iem_severity[sev_id],
109  mod_id, evt_id, iem_re[evt_id].ir_total,
110  (const char *)description);
111  else
112  M0_LOG(M0_INFO, "IEC: %c%c%3x%3x%4x: %s",
113  m0_motr_iem_severity[sev_id],
115  mod_id, evt_id, (const char *)description);
116 
117  M0_LOG(M0_INFO, "from %s:%s:%d",
118  (const char*)file, (const char*)function, line);
119 }
120 
121 #undef M0_TRACE_SUBSYSTEM
m0_motr_iem_event
Definition: iem.h:67
m0_motr_iem_module
Definition: iem.h:61
uint64_t ir_total
Definition: iem.c:46
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
const int M0_MOTR_IEM_COMPONENT_ID_MOTR
Definition: iem.c:34
struct m0_file file
Definition: di.c:36
uint64_t m0_time_t
Definition: time.h:37
#define M0_LOG(level,...)
Definition: trace.h:167
void m0_iem(const char *file, const char *function, int line, const enum m0_motr_iem_severity sev_id, const enum m0_motr_iem_module mod_id, const enum m0_motr_iem_event evt_id, const char *msg,...)
Definition: iem.c:58
void m0_console_printf(const char *fmt,...)
Definition: trace.c:801
m0_time_t ir_stamp
Definition: iem.c:44
#define PRIx64
Definition: types.h:61
static struct m0_iem_retrigger iem_re[M0_IEM_EVENT_NR]
Definition: iem.c:49
#define PRIu64
Definition: types.h:58
bool m0_time_is_in_past(m0_time_t t)
Definition: time.c:102
Definition: trace.h:482
m0_time_t m0_time_now(void)
Definition: time.c:134
Definition: iem.c:53
const char M0_MOTR_IEM_SOURCE_ID
Definition: iem.c:31
description
Definition: setup.py:30
Definition: iem.c:55
m0_time_t m0_time_add(const m0_time_t t1, const m0_time_t t2)
Definition: time.c:47
void m0_console_flush(void)
Definition: ktrace.c:165
m0_motr_iem_severity
Definition: iem.h:28
#define IS_IN_ARRAY(idx, array)
Definition: misc.h:311
#define M0_MKTIME(secs, ns)
Definition: time.h:86
uint64_t ir_niems
Definition: iem.c:45