This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gdb and dlopen



Damn reply vs. reply-all.




> 
> Amusingly, there are something like eight million calls to
> ptid_get_pid.  I'll send along a trivial patch to shrink the worst
> offenders.  I understand the opacity that functions over macros is
> going for here, but a function that does 'return a.b;' and gets called
> eight MILLION times is a little bit absurd, don't you think?  Absurd
> enough that it shows up as the second highest item on the profile.
> 

One of the ones I did was change infptrace.c, child_xfer_memory to
extract the PIDGET( inferior_ptid ) to a temporary variable at the top
of the function, thereby pulling it out of the loops, which reduced
the number of calls to ptid_get_pid from 164760313 to 1251627. I
though 2 orders of magnitude would be a good thing, but wasn't sure if
that was safe - didn't see why it wouldn't be, but this is my first
attempt at modifying gdb's source code...

I changed thread_db_thread_alive to cache the last result (i.e. if the
ptid passed in is the same as the last one, just return that value),
which I can imagine isn't safe to do in the general case, but is for
at least my case, presuming that thread_alive means that the thread is
still there and in a runnable state, and it cut the load time from 150
seconds to 66, so that seems to be where ~ 2/3rds the time is
spent.... (fyi, my changed version is attached, if you want to try)


- Kimball


static int
thread_db_thread_alive (ptid_t ptid)
{
  td_thrhandle_t th;
  td_thrinfo_t   ti;
  td_err_e       err;
  static ptid_t	 last_ptid = { -1, -1, -1 };
  static int	 last_retval	= -1;

  if ( last_ptid.pid == ptid.pid &&
	   last_ptid.lwp == ptid.lwp &&
	   last_ptid.tid == ptid.tid )
	  return last_retval;

  last_ptid = ptid;
  
  if (is_thread (ptid))
  {
      err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (ptid), &th);
      if (err != TD_OK)
	  {
		  last_retval = 0;
		  return 0;
	  }

	  err = td_thr_validate_p (&th);
	  if (err != TD_OK)
	  {
		  last_retval = 0;
		  return 0;
	  }

	  err = td_thr_get_info_p (&th, &ti);
	  if (err != TD_OK)
	  {
		  last_retval = 0;
		  return 0;
	  }

	  if (ti.ti_state == TD_THR_UNKNOWN ||
		  ti.ti_state == TD_THR_ZOMBIE)
	  {
		  last_retval = 0;
		  return 0;	/* A zombie thread. */
	  }

	  last_retval = 1;
	  return 1;
  }
  
  if (target_beneath->to_thread_alive)
  {
	  last_retval = target_beneath->to_thread_alive (ptid);
	  return last_retval;
  }

  last_retval = 0;
  return 0;
}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]