aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/run-time-clock.cc22
-rw-r--r--gdbsupport/run-time-clock.h26
2 files changed, 39 insertions, 9 deletions
diff --git a/gdbsupport/run-time-clock.cc b/gdbsupport/run-time-clock.cc
index 43da1d9..621ba77 100644
--- a/gdbsupport/run-time-clock.cc
+++ b/gdbsupport/run-time-clock.cc
@@ -38,13 +38,29 @@ timeval_to_microseconds (struct timeval *tv)
#endif
void
-run_time_clock::now (user_cpu_time_clock::time_point &user,
- system_cpu_time_clock::time_point &system) noexcept
+get_run_time (user_cpu_time_clock::time_point &user,
+ system_cpu_time_clock::time_point &system,
+ run_time_scope scope) noexcept
{
#ifdef HAVE_GETRUSAGE
struct rusage rusage;
+ int who;
- getrusage (RUSAGE_SELF, &rusage);
+ switch (scope)
+ {
+ case run_time_scope::thread:
+ who = RUSAGE_THREAD;
+ break;
+
+ case run_time_scope::process:
+ who = RUSAGE_SELF;
+ break;
+
+ default:
+ gdb_assert_not_reached ("invalid run_time_scope value");
+ }
+
+ getrusage (who, &rusage);
microseconds utime = timeval_to_microseconds (&rusage.ru_utime);
microseconds stime = timeval_to_microseconds (&rusage.ru_stime);
diff --git a/gdbsupport/run-time-clock.h b/gdbsupport/run-time-clock.h
index a961f4c..a985dbb 100644
--- a/gdbsupport/run-time-clock.h
+++ b/gdbsupport/run-time-clock.h
@@ -51,6 +51,26 @@ struct system_cpu_time_clock
static time_point now () noexcept = delete;
};
+/* Whether to measure time run time for the whole process or just one
+ thread. */
+
+enum class run_time_scope
+{
+ process,
+ thread,
+};
+
+/* Return the user/system time as separate time points, if
+ supported. If not supported, then the combined user+kernel time
+ is returned in USER and SYSTEM is set to zero.
+
+ SCOPE indicates whether to return the run time for the whole process or
+ just for the calling thread. */
+
+void get_run_time (user_cpu_time_clock::time_point &user,
+ system_cpu_time_clock::time_point &system,
+ run_time_scope scope) noexcept;
+
/* Count the total amount of time spent executing in userspace+kernel
mode. */
@@ -64,12 +84,6 @@ struct run_time_clock
static constexpr bool is_steady = true;
static time_point now () noexcept;
-
- /* Return the user/system time as separate time points, if
- supported. If not supported, then the combined user+kernel time
- is returned in USER and SYSTEM is set to zero. */
- static void now (user_cpu_time_clock::time_point &user,
- system_cpu_time_clock::time_point &system) noexcept;
};
#endif /* GDBSUPPORT_RUN_TIME_CLOCK_H */