[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:36:18 +08:00 committed by Xiang Xiao
parent 9694760eb8
commit bf957348ef
1 changed files with 34 additions and 6 deletions

View File

@ -188,6 +188,21 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
totalsize = 0;
/* Generate output for CPU Serial Number */
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d", cpu);
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
totalsize += copysize;
buffer += copysize;
buflen -= copysize;
if (buflen <= 0)
{
return totalsize;
}
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
/* Convert the for maximum time pre-emption disabled */
if (g_premp_max[cpu] > 0)
@ -206,15 +221,16 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
/* Generate output for maximum time pre-emption disabled */
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d,%lu.%09lu,",
cpu, (unsigned long)maxtime.tv_sec,
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
(unsigned long)maxtime.tv_sec,
(unsigned long)maxtime.tv_nsec);
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
totalsize += copysize;
buffer += copysize;
buflen -= copysize;
if (totalsize >= buflen)
if (buflen <= 0)
{
return totalsize;
}
@ -237,12 +253,26 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
/* Generate output for maximum time in a critical section */
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%lu.%09lu\n",
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
(unsigned long)maxtime.tv_sec,
(unsigned long)maxtime.tv_nsec);
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
totalsize += copysize;
buffer += copysize;
buflen -= copysize;
if (buflen <= 0)
{
return totalsize;
}
#endif
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "\n");
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
totalsize += copysize;
return totalsize;
}
@ -280,8 +310,6 @@ static ssize_t critmon_read(FAR struct file *filep, FAR char *buffer,
{
break;
}
offset += nbytes;
}
if (ret > 0)