18dffb485Schristos /* User/system CPU time clocks that follow the std::chrono interface. 2*5ba1f45fSchristos Copyright (C) 2016-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of GDB. 58dffb485Schristos 68dffb485Schristos This program is free software; you can redistribute it and/or modify 78dffb485Schristos it under the terms of the GNU General Public License as published by 88dffb485Schristos the Free Software Foundation; either version 3 of the License, or 98dffb485Schristos (at your option) any later version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, 128dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148dffb485Schristos GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 188dffb485Schristos 198dffb485Schristos #ifndef COMMON_RUN_TIME_CLOCK_H 208dffb485Schristos #define COMMON_RUN_TIME_CLOCK_H 218dffb485Schristos 228dffb485Schristos #include <chrono> 238dffb485Schristos 248dffb485Schristos /* Count the total amount of time spent executing in user mode. */ 258dffb485Schristos 268dffb485Schristos struct user_cpu_time_clock 278dffb485Schristos { 288dffb485Schristos using duration = std::chrono::microseconds; 298dffb485Schristos using rep = duration::rep; 308dffb485Schristos using period = duration::period; 318dffb485Schristos using time_point = std::chrono::time_point<user_cpu_time_clock>; 328dffb485Schristos 338dffb485Schristos static constexpr bool is_steady = true; 348dffb485Schristos 358dffb485Schristos /* Use run_time_clock::now instead. */ 368dffb485Schristos static time_point now () noexcept = delete; 378dffb485Schristos }; 388dffb485Schristos 398dffb485Schristos /* Count the total amount of time spent executing in kernel mode. */ 408dffb485Schristos 418dffb485Schristos struct system_cpu_time_clock 428dffb485Schristos { 438dffb485Schristos using duration = std::chrono::microseconds; 448dffb485Schristos using rep = duration::rep; 458dffb485Schristos using period = duration::period; 468dffb485Schristos using time_point = std::chrono::time_point<system_cpu_time_clock>; 478dffb485Schristos 488dffb485Schristos static constexpr bool is_steady = true; 498dffb485Schristos 508dffb485Schristos /* Use run_time_clock::now instead. */ 518dffb485Schristos static time_point now () noexcept = delete; 528dffb485Schristos }; 538dffb485Schristos 548dffb485Schristos /* Count the total amount of time spent executing in userspace+kernel 558dffb485Schristos mode. */ 568dffb485Schristos 578dffb485Schristos struct run_time_clock 588dffb485Schristos { 598dffb485Schristos using duration = std::chrono::microseconds; 608dffb485Schristos using rep = duration::rep; 618dffb485Schristos using period = duration::period; 628dffb485Schristos using time_point = std::chrono::time_point<run_time_clock>; 638dffb485Schristos 648dffb485Schristos static constexpr bool is_steady = true; 658dffb485Schristos 668dffb485Schristos static time_point now () noexcept; 678dffb485Schristos 688dffb485Schristos /* Return the user/system time as separate time points, if 698dffb485Schristos supported. If not supported, then the combined user+kernel time 708dffb485Schristos is returned in USER and SYSTEM is set to zero. */ 718dffb485Schristos static void now (user_cpu_time_clock::time_point &user, 728dffb485Schristos system_cpu_time_clock::time_point &system) noexcept; 738dffb485Schristos }; 748dffb485Schristos 758dffb485Schristos #endif /* COMMON_RUN_TIME_CLOCK_H */ 76