[Bug 253742] New: ksysguardd: inefficient read loop
Ortwin Glück
odi at odi.ch
Sun Oct 10 13:07:40 BST 2010
https://bugs.kde.org/show_bug.cgi?id=253742
Summary: ksysguardd: inefficient read loop
Product: kde
Version: 4.4
Platform: Gentoo Packages
OS/Version: Linux
Status: UNCONFIRMED
Severity: minor
Priority: NOR
Component: general
AssignedTo: unassigned-bugs at kde.org
ReportedBy: odi at odi.ch
Version: 4.4 (using KDE 4.4.5)
OS: Linux
ksysguardd.c uses an ineffient loop to read from a fd. This causes 1 syscall
per byte. Look at the following strace:
select(5, [0 4], NULL, NULL, NULL) = 1 (in [0])
read(0, "c", 1) = 1
read(0, "p", 1) = 1
read(0, "u", 1) = 1
read(0, "/", 1) = 1
read(0, "c", 1) = 1
read(0, "p", 1) = 1
read(0, "u", 1) = 1
read(0, "3", 1) = 1
read(0, "/", 1) = 1
read(0, "w", 1) = 1
read(0, "a", 1) = 1
read(0, "i", 1) = 1
read(0, "t", 1) = 1
read(0, "?", 1) = 1
read(0, "\n", 1) = 1
write(1, "CPU 4 Wait Load\t0\t100\t%\n", 24) = 24
write(1, "ksysguardd> ", 12) = 12
Reproducible: Always
Actual Results:
231 static int readCommand( int fd, char* cmdBuf, size_t len )
232 {
233 unsigned int i;
234 char c;
235 for ( i = 0; i < len; ++i )
236 {
237 int result = read( fd, &c, 1 );
238 if (result < 0)
239 return -1; /* Error */
240
241 if (result == 0) {
242 if (i == 0)
243 return -1; /* Connection lost */
244
245 break; /* End of data */
246 }
247
248 if (c == '\n')
249 break; /* End of line */
250
251 cmdBuf[ i ] = c;
252 }
253 cmdBuf[i] = '\0';
254
255 return i;
256 }
Reads from a fd should be buffered.
--
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the Unassigned-bugs
mailing list