avr: try calculating idle times.

This commit is contained in:
Martin Preuss
2023-04-10 23:33:24 +02:00
parent 6c8f8e19b2
commit eca6fc6efc
15 changed files with 315 additions and 7 deletions

85
aqhome/msg/msg_sysstats.c Normal file
View File

@@ -0,0 +1,85 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "aqhome/msg/msg_sysstats.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_SYSSTATS_SECONDS 0 /* 4 bytes */
#define AQH_MSG_OFFS_SYSSTATS_UID 4 /* 4 bytes */
#define AQH_MSG_OFFS_SYSSTATS_COMIRQS 8 /* 2 bytes */
#define AQH_MSG_OFFS_SYSSTATS_TIMERIRQS 10 /* 2 bytes */
#define AQH_MSG_OFFS_SYSSTATS_IDLEPERCENT 12 /* 1 byte */
#define AQH_MSG_MEMSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_IDLEPERCENT+1)
uint32_t AQH_SysStatsMsg_GetUid(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_UID, 0);
}
uint32_t AQH_SysStatsMsg_GetSeconds(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_SECONDS, 0);
}
uint16_t AQH_SysStatsMsg_GetComInterrupts(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_COMIRQS, 0);
}
uint16_t AQH_SysStatsMsg_GetTimerInterrupts(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_TIMERIRQS, 0);
}
uint8_t AQH_SysStatsMsg_GetIdlePercentage(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_IDLEPERCENT, 0);
}
void AQH_SysStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SYSSTATS %s (uid=0x%08x, uptime=%d, idle=%d, com irqs=%d, timer irqs=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
(unsigned int) AQH_SysStatsMsg_GetUid(msg),
AQH_SysStatsMsg_GetSeconds(msg),
AQH_SysStatsMsg_GetIdlePercentage(msg),
AQH_SysStatsMsg_GetComInterrupts(msg),
AQH_SysStatsMsg_GetTimerInterrupts(msg));
}