[BugFix]Command "critmon" error

Command "critmon" has some format errors and information errors, such as:

PRE-EMPTION CALLER            CSECTION CALLER               RUN         TIME             PID   DESCRIPTION
1.679000000                   3.704000000
                         None None             0     CPU0 IDLE
0.002000000                   0.003000000
                         None None             1     CPU1 IDLE
0.000000000                   0.000000000
                         None None             2     CPU2 IDLE
0.000000000                   0.000000000
                         None None             3     CPU3 IDLE
0.001000000                   0.001000000
                         None None             4     hpwork
0.002000000                   0.006000000
                         None None             5     nsh_main
0.000000000                   0.000000000
                         None None             6     critmon

After bug fix:

PRE-EMPTION CALLER            CSECTION CALLER               RUN              TIME             PID   DESCRIPTION
None                          None                          ---------------- ---------------- ----  CPU 0
None                          None                          ---------------- ---------------- ----  CPU 1
None                          None                          ---------------- ---------------- ----  CPU 2
None                          None                          ---------------- ---------------- ----  CPU 3
None                          None                          0.238000000      6.982000000      0     CPU0 IDLE
None                          None                          0.461000000      13.089000000     1     CPU1 IDLE
None                          None                          0.000000000      0.000000000      2     CPU2 IDLE
None                          None                          0.000000000      0.000000000      3     CPU3 IDLE
None                          None                          0.000000000      0.001000000      4     hpwork
None                          None                          0.000000000      0.010000000      5     nsh_main
None                          None                          0.000000000      0.000000000      46    critmon

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
wangzhi16 2024-08-14 20:42:11 +08:00 committed by Xiang Xiao
parent c2d478a93a
commit f638a21f89

View File

@ -120,7 +120,7 @@ static int critmon_process_directory(FAR struct dirent *entryp)
FAR char *maxcrit;
FAR char *maxrun;
FAR char *runtime;
FAR char *endptr;
FAR char *pos;
FILE *stream;
int len;
int ret;
@ -218,53 +218,56 @@ static int critmon_process_directory(FAR struct dirent *entryp)
* Output Format: X.XXXXXXXXX X.XXXXXXXXX X.XXXXXXXXX NNNNN <name>
*/
maxpreemp = g_critmon.line;
maxcrit = strchr(g_critmon.line, ',');
pos = critmon_isolate_value(g_critmon.line);
if (maxcrit != NULL)
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
maxpreemp = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*maxcrit++ = '\0';
maxrun = strchr(maxcrit, ',');
if (maxrun != NULL)
{
*maxrun++ = '\0';
runtime = strchr(maxrun, ',');
if (runtime != NULL)
{
*runtime++ = '\0';
endptr = strchr(runtime, '\n');
if (endptr != NULL)
{
*endptr = '\0';
}
}
else
{
runtime = "None";
}
}
else
{
maxrun = "None";
runtime = "None";
}
*pos++ = '\0';
}
else
#else
maxpreemp = "None";
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
maxcrit = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
maxcrit = "None";
maxrun = "None";
runtime = "None";
*pos++ = '\0';
}
#else
maxcrit = "None";
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
maxrun = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*pos++ = '\0';
}
runtime = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*pos++ = '\0';
}
#else
maxrun = "None";
runtime = "None";
#endif
/* Finally, output the stack info that we gleaned from the procfs */
#if CONFIG_TASK_NAME_SIZE > 0
printf("%11s %11s %11s %-16s %-5s %s\n",
printf("%-29s %-29s %-16s %-16s %-5s %s\n",
maxpreemp, maxcrit, maxrun, runtime, entryp->d_name, name);
#else
printf("%11s %11s %11s %16s %5s\n",
printf("%-29s %-29s %16s %16s %5s\n",
maxpreemp, maxcrit, maxrun, runtime, entryp->d_name);
#endif
@ -320,7 +323,7 @@ static void critmon_global_crit(void)
FAR char *cpu;
FAR char *maxpreemp;
FAR char *maxcrit;
FAR char *endptr;
FAR char *pos;
FILE *stream;
int errcode;
int ret;
@ -357,36 +360,40 @@ static void critmon_global_crit(void)
* Output Format: X.XXXXXXXXX X.XXXXXXXXX CPU X
*/
cpu = g_critmon.line;
maxpreemp = strchr(g_critmon.line, ',');
pos = critmon_isolate_value(g_critmon.line);
cpu = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*pos++ = '\0';
}
if (maxpreemp != NULL)
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
maxpreemp = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*maxpreemp++ = '\0';
maxcrit = strchr(maxpreemp, ',');
if (maxcrit != NULL)
{
*maxcrit++ = '\0';
endptr = strchr(maxcrit, '\n');
if (endptr != NULL)
{
*endptr = '\0';
}
}
else
{
maxcrit = "None";
}
*pos++ = '\0';
}
else
#else
maxpreemp = "None";
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
maxcrit = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
maxpreemp = "None";
maxcrit = "None";
*pos++ = '\0';
}
#else
maxcrit = "None";
#endif
/* Finally, output the stack info that we gleaned from the procfs */
printf("%11s %11s ----------- ---------------- ---- CPU %s\n",
printf("%-29s %-29s ---------------- ---------------- ---- "
"CPU %s\n",
maxpreemp, maxcrit, cpu);
}
@ -410,10 +417,11 @@ static int critmon_list_once(void)
/* Output a Header */
#if CONFIG_TASK_NAME_SIZE > 0
printf("PRE-EMPTION CSECTION RUN TIME "
"PID DESCRIPTION\n");
printf("PRE-EMPTION CALLER CSECTION CALLER "
"RUN TIME PID DESCRIPTION\n");
#else
printf("PRE-EMPTION CSECTION RUN TIME PID\n");
printf("PRE-EMPTION CALLER CSECTION CALLER "
"RUN TIME PID\n");
#endif
/* Should global usage first */