Skip to content

Commit

Permalink
[BugFix]Command "critmon" error
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wangzhi-art authored and xiaoxiang781216 committed Aug 24, 2024
1 parent c2d478a commit f638a21
Showing 1 changed file with 69 additions and 61 deletions.
130 changes: 69 additions & 61 deletions system/critmon/critmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
*pos++ = '\0';
}
#else
maxpreemp = "None";
#endif

maxrun = strchr(maxcrit, ',');
if (maxrun != NULL)
{
*maxrun++ = '\0';
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
maxcrit = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*pos++ = '\0';
}
#else
maxcrit = "None";
#endif

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";
}
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
maxrun = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
*pos++ = '\0';
}
else

runtime = pos;
pos = strchr(pos, ',');
if (pos != NULL)
{
maxcrit = "None";
maxrun = "None";
runtime = "None";
*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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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 */
Expand Down

0 comments on commit f638a21

Please sign in to comment.