dab305567f5e2aca678602f04a72108513694e5b
[platform/core/system/dlog.git] / include / loglimiter.h
1 /*  MIT License
2  *
3  * Copyright (c) 2013-2020 Samsung Electronics Co., Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 #ifndef _LOGLIMITER_H_
24 #define _LOGLIMITER_H_
25
26 /* Define maximum logging speed, everything greater means unlimited.
27  * Maximum possible value is INT_MAX-2 */
28 #define __LOG_LIMITER_LIMIT_MAX        (10*1000)
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <stddef.h>
35
36 #include <logconfig.h>
37 #include <ptrs_list.h>
38
39 struct rule;
40
41 struct limiter_limits {
42         int tag_and_prio;
43         int tag;
44         int prio;
45         int global;
46 };
47
48 struct pid_limit {
49         pid_t pid;
50         size_t limit;
51 };
52
53 void __log_limiter_destroy(void);
54
55 struct pass_log_result {
56         enum {
57                 DECISION_ALLOWED,
58                 DECISION_DENIED,
59                 DECISION_TAG_LIMIT_EXCEEDED_MESSAGE,
60                 DECISION_PID_LIMIT_EXCEEDED_MESSAGE,
61         } decision;
62
63         int logs_per_period;
64         int period_s;
65 };
66
67 struct pass_log_result __log_limiter_pass_log(const char *tag, int prio);
68
69 int __log_limiter_create(const struct log_config *config);
70
71 struct limiter_limits __log_limiter_get_limits(const char *tag, int prio);
72
73 void __log_limiter_update(const struct log_config *config);
74
75 int __log_limiter_dump_rule(struct rule **, char *, const size_t);
76
77 // Note: result only valid until next __log_limiter_{update,destroy}
78 list_head __log_limiter_get_pid_limits();
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif /* _LOGLIMITER_H_ */