LCOV - code coverage report
Current view: top level - system - SystemStats.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 4 18 22.2 %
Date: 2024-02-15 08:20:41 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2020 Project CHIP Authors
       4             :  *    Copyright (c) 2016-2017 Nest Labs, Inc.
       5             :  *
       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
       9             :  *
      10             :  *        http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      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.
      17             :  */
      18             : 
      19             : /**
      20             :  * @file
      21             :  *  This file implements the CHIP API to collect statistics
      22             :  *  on the state of CHIP, Inet and System resources
      23             :  */
      24             : 
      25             : // Include local headers
      26             : #include <system/SystemTimer.h>
      27             : 
      28             : // Include module header
      29             : #include <system/SystemStats.h>
      30             : 
      31             : #include <lib/support/SafeInt.h>
      32             : #include <platform/LockTracker.h>
      33             : 
      34             : #include <string.h>
      35             : 
      36             : namespace chip {
      37             : namespace System {
      38             : namespace Stats {
      39             : 
      40             : static const Label sStatsStrings[chip::System::Stats::kNumEntries] = {
      41             : #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_PBUF_FROM_CUSTOM_POOLS
      42             : #define LWIP_PBUF_MEMPOOL(name, num, payload, desc) "SystemLayer_Num" desc,
      43             : #include "lwippools.h"
      44             : #undef LWIP_PBUF_MEMPOOL
      45             : #else
      46             :     "Packet Buffers",
      47             : #endif
      48             :     "Timers",
      49             : #if INET_CONFIG_NUM_TCP_ENDPOINTS
      50             :     "TCP endpoints",
      51             : #endif
      52             : #if INET_CONFIG_NUM_UDP_ENDPOINTS
      53             :     "UDP endpoints",
      54             : #endif
      55             :     "Exchange contexts",
      56             :     "Unsolicited message handlers",
      57             :     "Platform events",
      58             : };
      59             : 
      60             : count_t sResourcesInUse[kNumEntries];
      61             : count_t sHighWatermarks[kNumEntries];
      62             : 
      63           0 : const Label * GetStrings()
      64             : {
      65           0 :     return sStatsStrings;
      66             : }
      67             : 
      68     8377950 : count_t * GetResourcesInUse()
      69             : {
      70     8377950 :     return sResourcesInUse;
      71             : }
      72             : 
      73     4185972 : count_t * GetHighWatermarks()
      74             : {
      75     4185972 :     return sHighWatermarks;
      76             : }
      77             : 
      78           0 : void UpdateSnapshot(Snapshot & aSnapshot)
      79             : {
      80           0 :     memcpy(&aSnapshot.mResourcesInUse, &sResourcesInUse, sizeof(aSnapshot.mResourcesInUse));
      81           0 :     memcpy(&aSnapshot.mHighWatermarks, &sHighWatermarks, sizeof(aSnapshot.mHighWatermarks));
      82             : 
      83             :     SYSTEM_STATS_UPDATE_LWIP_PBUF_COUNTS();
      84           0 : }
      85             : 
      86           0 : bool Difference(Snapshot & result, Snapshot & after, Snapshot & before)
      87             : {
      88             :     int i;
      89           0 :     bool leak = false;
      90             : 
      91           0 :     for (i = 0; i < kNumEntries; i++)
      92             :     {
      93             :         // TODO: These casts can be bogus.  https://github.com/project-chip/connectedhomeip/issues/2949
      94           0 :         result.mResourcesInUse[i] = static_cast<count_t>(after.mResourcesInUse[i] - before.mResourcesInUse[i]);
      95           0 :         result.mHighWatermarks[i] = static_cast<count_t>(after.mHighWatermarks[i] - before.mHighWatermarks[i]);
      96             : 
      97           0 :         if (result.mResourcesInUse[i] > 0)
      98             :         {
      99           0 :             leak = true;
     100             :         }
     101             :     }
     102             : 
     103           0 :     return leak;
     104             : }
     105             : 
     106             : #if CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
     107             : 
     108             : void UpdateLwipPbufCounts(void)
     109             : {
     110             : #if LWIP_PBUF_FROM_CUSTOM_POOLS
     111             :     size_t lwip_pool_idx = PBUF_CUSTOM_POOL_IDX_END;
     112             :     size_t system_idx    = 0;
     113             : 
     114             :     while (lwip_pool_idx <= PBUF_CUSTOM_POOL_IDX_START)
     115             :     {
     116             :         chip::System::Stats::GetResourcesInUse()[system_idx] = MEMP_STATS_GET(used, lwip_pool_idx);
     117             :         chip::System::Stats::GetHighWatermarks()[system_idx] = MEMP_STATS_GET(max, lwip_pool_idx);
     118             :         lwip_pool_idx++;
     119             :         system_idx++;
     120             :     }
     121             : 
     122             : #else // LWIP_PBUF_FROM_CUSTOM_POOLS
     123             : 
     124             :     chip::System::Stats::GetResourcesInUse()[kSystemLayer_NumPacketBufs] = MEMP_STATS_GET(used, MEMP_PBUF_POOL);
     125             :     chip::System::Stats::GetHighWatermarks()[kSystemLayer_NumPacketBufs] = MEMP_STATS_GET(max, MEMP_PBUF_POOL);
     126             : 
     127             : #endif // LWIP_PBUF_FROM_CUSTOM_POOLS
     128             : }
     129             : #endif // CHIP_SYSTEM_CONFIG_USE_LWIP && LWIP_STATS && MEMP_STATS
     130             : 
     131             : } // namespace Stats
     132             : } // namespace System
     133             : } // namespace chip

Generated by: LCOV version 1.14