aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/run-time-clock.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport/run-time-clock.cc')
-rw-r--r--gdbsupport/run-time-clock.cc43
1 files changed, 40 insertions, 3 deletions
diff --git a/gdbsupport/run-time-clock.cc b/gdbsupport/run-time-clock.cc
index 43da1d9..cda60b0 100644
--- a/gdbsupport/run-time-clock.cc
+++ b/gdbsupport/run-time-clock.cc
@@ -37,14 +37,51 @@ timeval_to_microseconds (struct timeval *tv)
}
#endif
+/* See run-time-clock.h. */
+
+bool
+get_run_time_thread_scope_available ()
+{
+#if defined HAVE_GETRUSAGE && defined RUSAGE_THREAD
+ return true;
+#else
+ return false;
+#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
+
+ /* If we can't provide thread scope run time usage, fallback to
+ process scope. This will at least be right if GDB is built
+ without threading support in the first place (or is set to use
+ zero worker threads). */
+# ifndef RUSAGE_THREAD
+# define RUSAGE_THREAD RUSAGE_SELF
+# endif
+
struct rusage rusage;
+ int who;
+
+ 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 (RUSAGE_SELF, &rusage);
+ getrusage (who, &rusage);
microseconds utime = timeval_to_microseconds (&rusage.ru_utime);
microseconds stime = timeval_to_microseconds (&rusage.ru_stime);