1 1.1 christos /* Support for GDB maintenance commands. 2 1.1.1.10 christos Copyright (C) 2013-2025 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of GDB. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 1.1 christos 19 1.1.1.9 christos #ifndef GDB_MAINT_H 20 1.1.1.9 christos #define GDB_MAINT_H 21 1.1 christos 22 1.1.1.6 christos #include "gdbsupport/run-time-clock.h" 23 1.1.1.4 christos #include <chrono> 24 1.1.1.4 christos 25 1.1.1.10 christos struct obj_section; 26 1.1.1.10 christos struct objfile; 27 1.1.1.10 christos 28 1.1 christos extern void set_per_command_time (int); 29 1.1 christos 30 1.1 christos extern void set_per_command_space (int); 31 1.1 christos 32 1.1.1.8 christos /* Update the thread pool for the desired number of threads. */ 33 1.1.1.8 christos 34 1.1.1.8 christos extern void update_thread_pool_size (); 35 1.1.1.8 christos 36 1.1.1.4 christos /* Records a run time and space usage to be used as a base for 37 1.1.1.4 christos reporting elapsed time or change in space. */ 38 1.1 christos 39 1.1.1.4 christos class scoped_command_stats 40 1.1.1.4 christos { 41 1.1.1.4 christos public: 42 1.1.1.4 christos 43 1.1.1.4 christos explicit scoped_command_stats (bool msg_type); 44 1.1.1.4 christos ~scoped_command_stats (); 45 1.1.1.4 christos 46 1.1.1.4 christos private: 47 1.1.1.4 christos 48 1.1.1.6 christos DISABLE_COPY_AND_ASSIGN (scoped_command_stats); 49 1.1.1.6 christos 50 1.1.1.6 christos /* Print the time, along with a string. */ 51 1.1.1.6 christos void print_time (const char *msg); 52 1.1.1.4 christos 53 1.1.1.4 christos /* Zero if the saved time is from the beginning of GDB execution. 54 1.1.1.4 christos One if from the beginning of an individual command execution. */ 55 1.1.1.4 christos bool m_msg_type; 56 1.1.1.4 christos /* Track whether the stat was enabled at the start of the command 57 1.1.1.4 christos so that we can avoid printing anything if it gets turned on by 58 1.1.1.4 christos the current command. */ 59 1.1.1.8 christos bool m_time_enabled : 1; 60 1.1.1.8 christos bool m_space_enabled : 1; 61 1.1.1.8 christos bool m_symtab_enabled : 1; 62 1.1.1.4 christos run_time_clock::time_point m_start_cpu_time; 63 1.1.1.4 christos std::chrono::steady_clock::time_point m_start_wall_time; 64 1.1.1.10 christos #ifdef HAVE_USEFUL_SBRK 65 1.1.1.4 christos long m_start_space; 66 1.1.1.10 christos #endif 67 1.1.1.4 christos /* Total number of symtabs (over all objfiles). */ 68 1.1.1.4 christos int m_start_nr_symtabs; 69 1.1.1.4 christos /* A count of the compunits. */ 70 1.1.1.4 christos int m_start_nr_compunit_symtabs; 71 1.1.1.4 christos /* Total number of blocks. */ 72 1.1.1.4 christos int m_start_nr_blocks; 73 1.1.1.4 christos }; 74 1.1 christos 75 1.1.1.10 christos /* If true, display time usage both at startup and for each command. */ 76 1.1.1.10 christos 77 1.1.1.10 christos extern bool per_command_time; 78 1.1.1.10 christos 79 1.1.1.10 christos /* RAII structure used to measure the time spent by the current thread in a 80 1.1.1.10 christos given scope. */ 81 1.1.1.10 christos 82 1.1.1.10 christos struct scoped_time_it 83 1.1.1.10 christos { 84 1.1.1.10 christos /* WHAT is the prefix to show when the summary line is printed. */ 85 1.1.1.10 christos scoped_time_it (const char *what, bool enabled = per_command_time); 86 1.1.1.10 christos 87 1.1.1.10 christos DISABLE_COPY_AND_ASSIGN (scoped_time_it); 88 1.1.1.10 christos ~scoped_time_it (); 89 1.1.1.10 christos 90 1.1.1.10 christos private: 91 1.1.1.10 christos bool m_enabled; 92 1.1.1.10 christos 93 1.1.1.10 christos /* Summary line prefix. */ 94 1.1.1.10 christos const char *m_what; 95 1.1.1.10 christos 96 1.1.1.10 christos /* User time at the start of execution. */ 97 1.1.1.10 christos user_cpu_time_clock::time_point m_start_user; 98 1.1.1.10 christos 99 1.1.1.10 christos /* System time at the start of execution. */ 100 1.1.1.10 christos system_cpu_time_clock::time_point m_start_sys; 101 1.1.1.10 christos 102 1.1.1.10 christos /* Wall-clock time at the start of execution. */ 103 1.1.1.10 christos std::chrono::steady_clock::time_point m_start_wall; 104 1.1.1.10 christos }; 105 1.1.1.10 christos 106 1.1.1.7 christos extern obj_section *maint_obj_section_from_bfd_section (bfd *abfd, 107 1.1.1.7 christos asection *asection, 108 1.1.1.7 christos objfile *ofile); 109 1.1.1.9 christos #endif /* GDB_MAINT_H */ 110