3131
3232#define XTOP_API_URI "/api/all"
3333#define XTOP_TOTAL_LEN 5
34- #define XTOP_CPU_EXTRA_DEFAULT ((uint16_t)-1)
34+ #define XTOP_CPU_EXTRA_MIN 2
3535
3636#define XTOP_CPU_HEADER " "\
3737 "CPU IDL "\
@@ -78,7 +78,8 @@ typedef struct xtop_args_ {
7878 char sKey [XSTR_MIN ];
7979
8080 size_t nIntervalU ;
81- uint16_t nCPUExtraLimit ;
81+ uint16_t nCPUExtraMin ;
82+ uint16_t nIfaceCount ;
8283 uint16_t nPort ;
8384 uint8_t nSort ;
8485 xpid_t nPID ;
@@ -129,7 +130,7 @@ void XTOPApp_DisplayUsage(const char *pName)
129130 printf (" %s [-U <user>] [-P <pass>] [-K <key>] [-c] [-v] [-x] [-h]\n\n" , XTOPApp_WhiteSpace (nLength ));
130131
131132 printf ("Options are:\n" );
132- printf (" %s-e%s <count> # Limit extra CPU info to given number \n" , XSTR_CLR_CYAN , XSTR_FMT_RESET );
133+ printf (" %s-e%s <count> # Minimum count of extra CPU info\n" , XSTR_CLR_CYAN , XSTR_FMT_RESET );
133134 printf (" %s-i%s <iface> # Interface name to display on top\n" , XSTR_CLR_CYAN , XSTR_FMT_RESET );
134135 printf (" %s-m%s <seconds> # Monitoring interval seconds\n" , XSTR_CLR_CYAN , XSTR_FMT_RESET );
135136 printf (" %s-t%s <type> # Sort result by selected type%s*%s\n" , XSTR_CLR_CYAN , XSTR_FMT_RESET , XSTR_CLR_RED , XSTR_FMT_RESET );
@@ -193,7 +194,8 @@ int XTOPApp_ParseArgs(xtop_args_t *pArgs, int argc, char *argv[])
193194 xstrnul (pArgs -> sToken );
194195 xstrnul (pArgs -> sKey );
195196
196- pArgs -> nCPUExtraLimit = XTOP_CPU_EXTRA_DEFAULT ;
197+ pArgs -> nCPUExtraMin = XTOP_CPU_EXTRA_MIN ;
198+ pArgs -> nIfaceCount = 0 ;
197199 pArgs -> nIntervalU = 0 ;
198200 pArgs -> nPort = 0 ;
199201 pArgs -> nPID = 0 ;
@@ -230,7 +232,7 @@ int XTOPApp_ParseArgs(xtop_args_t *pArgs, int argc, char *argv[])
230232 pArgs -> nSort = XTOPApp_GetSortType (optarg );
231233 break ;
232234 case 'e' :
233- pArgs -> nCPUExtraLimit = atoi (optarg );
235+ pArgs -> nCPUExtraMin = atoi (optarg );
234236 break ;
235237 case 'm' :
236238 pArgs -> nIntervalU = atoi (optarg );
@@ -667,9 +669,14 @@ XSTATUS XTOPApp_AddCPUExtra(xcli_win_t *pWin, xtop_args_t *pArgs, xcli_bar_t *pB
667669 XSTATUS nStatus = XTOPApp_AddCPUInfo (pWin , & pCPU -> sum );
668670 if (nStatus <= 0 ) return nStatus ;
669671
672+ size_t nOccupiedLines = pWin -> lines .nUsed + pArgs -> nIfaceCount + 3 ;
670673 uint16_t i , nCount = pCPU -> nCoreCount ;
671- if (pArgs -> nCPUExtraLimit != XTOP_CPU_EXTRA_DEFAULT )
672- nCount = XSTD_MIN (pCPU -> nCoreCount , pArgs -> nCPUExtraLimit );
674+
675+ while (nOccupiedLines + nCount > pWin -> frame .nRows )
676+ {
677+ if (nCount <= pArgs -> nCPUExtraMin ) break ;
678+ nCount -- ;
679+ }
673680
674681 if ((pArgs -> nSort && pCPU -> nCoreCount &&
675682 pArgs -> nSort != XTOP_SORT_NAME &&
@@ -824,6 +831,7 @@ XSTATUS XTOPApp_AddNetworkInfo(xcli_win_t *pWin, xtop_args_t *pArgs, xarray_t *p
824831 xstrncat (sLine , sizeof (sLine ), "%s" , sRound );
825832
826833 XWindow_AddAligned (pWin , sLine , XSTR_BACK_BLUE , XCLI_LEFT );
834+ pArgs -> nIfaceCount = 0 ;
827835
828836 if (nTrackID >= 0 )
829837 {
@@ -835,7 +843,11 @@ XSTATUS XTOPApp_AddNetworkInfo(xcli_win_t *pWin, xtop_args_t *pArgs, xarray_t *p
835843 {
836844 if (nTrackID >= 0 && i == nTrackID ) continue ;
837845 xnet_iface_t * pIface = (xnet_iface_t * )XArray_GetData (pIfaces , i );
838- if (pIface != NULL ) XTOPApp_AddInterface (pWin , pArgs , nMaxIPLen , pIface , nLength );
846+ if (pIface != NULL )
847+ {
848+ XTOPApp_AddInterface (pWin , pArgs , nMaxIPLen , pIface , nLength );
849+ pArgs -> nIfaceCount ++ ;
850+ }
839851 }
840852
841853 nSpacePadding = XTOPApp_GetIfaceSpacePadding (pWin , XFALSE );
@@ -1659,7 +1671,7 @@ int main(int argc, char *argv[])
16591671 XTOPApp_AddCPULoadBar (& win , & bar , & cpuStats );
16601672 XTOPApp_AddOverallBar (& win , & bar , & memInfo , & cpuStats );
16611673
1662- if (args .nCPUExtraLimit > 0 )
1674+ if (args .nCPUExtraMin > 0 )
16631675 {
16641676 XWindow_AddEmptyLine (& win );
16651677 XTOPApp_AddCPUExtra (& win , & args , & bar , & memInfo , & cpuStats );
0 commit comments