3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file declares the CHIP API to collect statistics
22 * on the state of CHIP, Inet and System resources
27 // Include standard C library limit macros
28 #ifndef __STDC_LIMIT_MACROS
29 #define __STDC_LIMIT_MACROS
32 // Include configuration headers
33 #include <core/CHIPConfig.h>
34 #include <inet/InetConfig.h>
36 // Include dependent headers
37 #include <support/DLLUtil.h>
39 #if CHIP_SYSTEM_CONFIG_USE_LWIP
42 #include <lwip/pbuf.h>
43 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
53 #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_PBUF_FROM_CUSTOM_POOLS
54 #define LWIP_PBUF_MEMPOOL(name, num, payload, desc) kSystemLayer_Num##name,
55 #include "lwippools.h"
56 #undef LWIP_PBUF_MEMPOOL
58 kSystemLayer_NumPacketBufs,
60 kSystemLayer_NumTimers,
61 #if INET_CONFIG_NUM_RAW_ENDPOINTS
64 #if INET_CONFIG_NUM_TCP_ENDPOINTS
67 #if INET_CONFIG_NUM_UDP_ENDPOINTS
70 #if INET_CONFIG_NUM_DNS_RESOLVERS
71 kInetLayer_NumDNSResolvers,
73 kExchangeMgr_NumContexts,
74 kExchangeMgr_NumUMHandlers,
75 kExchangeMgr_NumBindings,
76 kMessageLayer_NumConnections,
80 typedef int8_t count_t;
81 #define PRI_CHIP_SYS_STATS_COUNT PRId8
82 #define CHIP_SYS_STATS_COUNT_MAX INT8_MAX
84 extern count_t ResourcesInUse[kNumEntries];
85 extern count_t HighWatermarks[kNumEntries];
90 count_t mResourcesInUse[kNumEntries];
91 count_t mHighWatermarks[kNumEntries];
94 bool Difference(Snapshot & result, Snapshot & after, Snapshot & before);
95 void UpdateSnapshot(Snapshot & aSnapshot);
96 count_t * GetResourcesInUse();
97 count_t * GetHighWatermarks();
99 #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
100 void UpdateLwipPbufCounts(void);
103 typedef const char * Label;
104 const Label * GetStrings();
107 } // namespace System
110 #if CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS
112 #define SYSTEM_STATS_INCREMENT(entry) \
115 chip::System::Stats::count_t new_value = ++(chip::System::Stats::GetResourcesInUse()[entry]); \
116 if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \
118 chip::System::Stats::GetHighWatermarks()[entry] = new_value; \
122 #define SYSTEM_STATS_DECREMENT(entry) \
125 chip::System::Stats::GetResourcesInUse()[entry]--; \
128 #define SYSTEM_STATS_DECREMENT_BY_N(entry, count) \
131 chip::System::Stats::GetResourcesInUse()[entry] -= (count); \
134 #define SYSTEM_STATS_SET(entry, count) \
137 chip::System::Stats::count_t new_value = chip::System::Stats::GetResourcesInUse()[entry] = (count); \
138 if (chip::System::Stats::GetHighWatermarks()[entry] < new_value) \
140 chip::System::Stats::GetHighWatermarks()[entry] = new_value; \
144 #define SYSTEM_STATS_RESET(entry) \
147 chip::System::Stats::GetResourcesInUse()[entry] = 0; \
150 #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
151 #define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS() \
154 chip::System::Stats::UpdateLwipPbufCounts(); \
156 #else // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
157 #define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS()
158 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
160 #else // CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS
162 #define SYSTEM_STATS_INCREMENT(entry)
164 #define SYSTEM_STATS_DECREMENT(entry)
166 #define SYSTEM_STATS_DECREMENT_BY_N(entry, count)
168 #define SYSTEM_STATS_RESET(entry)
170 #define SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS()
172 #endif // CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS