Skip to content

Commit bf95734

Browse files
wangzhi16xiaoxiang781216
authored andcommitted
[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>
1 parent 9694760 commit bf95734

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

fs/procfs/fs_procfscritmon.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
188188

189189
totalsize = 0;
190190

191+
/* Generate output for CPU Serial Number */
192+
193+
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d", cpu);
194+
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
195+
196+
totalsize += copysize;
197+
buffer += copysize;
198+
buflen -= copysize;
199+
200+
if (buflen <= 0)
201+
{
202+
return totalsize;
203+
}
204+
205+
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
191206
/* Convert the for maximum time pre-emption disabled */
192207

193208
if (g_premp_max[cpu] > 0)
@@ -206,15 +221,16 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
206221

207222
/* Generate output for maximum time pre-emption disabled */
208223

209-
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%d,%lu.%09lu,",
210-
cpu, (unsigned long)maxtime.tv_sec,
224+
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
225+
(unsigned long)maxtime.tv_sec,
211226
(unsigned long)maxtime.tv_nsec);
212227
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
213228

214229
totalsize += copysize;
215230
buffer += copysize;
231+
buflen -= copysize;
216232

217-
if (totalsize >= buflen)
233+
if (buflen <= 0)
218234
{
219235
return totalsize;
220236
}
@@ -237,12 +253,26 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
237253

238254
/* Generate output for maximum time in a critical section */
239255

240-
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "%lu.%09lu\n",
256+
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, ",%lu.%09lu",
241257
(unsigned long)maxtime.tv_sec,
242258
(unsigned long)maxtime.tv_nsec);
243259
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
244260

245261
totalsize += copysize;
262+
buffer += copysize;
263+
buflen -= copysize;
264+
265+
if (buflen <= 0)
266+
{
267+
return totalsize;
268+
}
269+
#endif
270+
271+
linesize = procfs_snprintf(attr->line, CRITMON_LINELEN, "\n");
272+
copysize = procfs_memcpy(attr->line, linesize, buffer, buflen, offset);
273+
274+
totalsize += copysize;
275+
246276
return totalsize;
247277
}
248278

@@ -280,8 +310,6 @@ static ssize_t critmon_read(FAR struct file *filep, FAR char *buffer,
280310
{
281311
break;
282312
}
283-
284-
offset += nbytes;
285313
}
286314

287315
if (ret > 0)

0 commit comments

Comments
 (0)