[PATCH v2] trace-record: slow down trace_waitpid loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



trace_waitpid() loop hogs one CPU during trace-cmd record. Add a delay there to
slow down the loop, to reduce the CPU load.

Signed-off-by: Vincent Stehlé <vincent.stehle@xxxxxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>

---


Changes since v1:
- Use nanosleep and sleep_time from command line.


 trace-record.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/trace-record.c b/trace-record.c
index 18e2e2d..a230fde 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -837,6 +837,7 @@ static pid_t trace_waitpid(enum trace_type type, pid_t pid, int *status, int opt
 	struct timeval tv = { 1, 0 };
 	int ret;
 	int profile = (type & TRACE_TYPE_PROFILE) == TRACE_TYPE_PROFILE;
+	struct timespec req;
 
 	options |= WNOHANG;
 
@@ -847,6 +848,11 @@ static pid_t trace_waitpid(enum trace_type type, pid_t pid, int *status, int opt
 
 		if (type & TRACE_TYPE_STREAM)
 			trace_stream_read(pids, recorder_threads, &tv, profile);
+
+		req.tv_sec = sleep_time / 1000000;
+		req.tv_nsec = (sleep_time % 1000000) * 1000;
+		nanosleep(&req, NULL);
+
 	} while (1);
 }
 #ifndef NO_PTRACE
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-trace-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux