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