Back to index

glibc  2.9
Defines | Functions | Variables
profil.c File Reference
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <hurd.h>
#include <mach/mach4.h>
#include <mach/pc_sample.h>
#include <cthreads.h>
#include <assert.h>
#include <libc-internal.h>
#include <mach/mig_support.h>
#include <../mach/RPC_task_get_sampled_pcs.c>

Go to the source code of this file.

Defines

#define MAX_PC_SAMPLES   512 /* XXX ought to be exported in kernel hdr */
#define __mig_put_reply_port(foo)
#define __mig_get_reply_port()   profil_reply_port
#define mig_external   static
#define weak_alias(a, b)
#define __vm_deallocate_rpc   profil_vm_deallocate
#define __task_get_sampled_pcs   profil_task_get_sampled_pcs

Functions

static kern_return_t profil_task_get_sampled_pcs (mach_port_t, sampled_pc_seqno_t *, sampled_pc_array_t, mach_msg_type_number_t *)
static void fetch_samples (void)
static void profile_waiter (void)
static error_t update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
int __profile_frequency (void)
 libc_hidden_def (__profile_frequency)
 weak_alias (__profil, profil)
static void fork_profil_prepare (void)
 text_set_element (_hurd_fork_prepare_hook, fork_profil_prepare)
static void fork_profil_parent (void)
 text_set_element (_hurd_fork_parent_hook, fork_profil_parent)
static void fork_profil_child (void)
 text_set_element (_hurd_fork_child_hook, fork_profil_child)

Variables

static thread_t profile_thread = MACH_PORT_NULL
static u_shortsamples
static size_t maxsamples
static size_t pc_offset
static size_t sample_scale
static sampled_pc_seqno_t seqno
static spin_lock_t lock = SPIN_LOCK_INITIALIZER
static mach_msg_timeout_t collector_timeout
static int profile_tick
static mach_port_t profil_reply_port

Define Documentation

#define __mig_get_reply_port (   void)    profil_reply_port

Definition at line 271 of file profil.c.

#define __mig_put_reply_port (   foo)

Definition at line 267 of file profil.c.

Definition at line 282 of file profil.c.

#define __vm_deallocate_rpc   profil_vm_deallocate

Definition at line 281 of file profil.c.

#define MAX_PC_SAMPLES   512 /* XXX ought to be exported in kernel hdr */

Definition at line 31 of file profil.c.

#define mig_external   static

Definition at line 274 of file profil.c.

#define weak_alias (   a,
  b 
)

Definition at line 278 of file profil.c.


Function Documentation

Definition at line 102 of file profil.c.

{
  return profile_tick;
}
static void fetch_samples ( void  ) [static]

Here is the caller graph for this function:

static void fork_profil_child ( void  ) [static]

Definition at line 223 of file profil.c.

{
  u_short *sb;
  size_t n, o, ss;
  error_t err;

  __spin_unlock (&lock);

  if (profile_thread != MACH_PORT_NULL)
    {
      __mach_port_deallocate (__mach_task_self (), profile_thread);
      profile_thread = MACH_PORT_NULL;
    }

  sb = samples;
  samples = NULL;
  n = maxsamples;
  maxsamples = 0;
  o = pc_offset;
  pc_offset = 0;
  ss = sample_scale;
  sample_scale = 0;

  if (ss != 0)
    {
      err = update_waiter (sb, n * sizeof *sb, o, ss);
      assert_perror (err);
    }
}

Here is the call graph for this function:

static void fork_profil_parent ( void  ) [static]

Definition at line 214 of file profil.c.

Here is the call graph for this function:

static void fork_profil_prepare ( void  ) [static]

Definition at line 206 of file profil.c.

{
  __spin_lock (&lock);
}

Here is the call graph for this function:

Definition at line 106 of file profil.c.

{
  error_t err;

  __spin_lock (&lock);

  if (scale == 0)
    {
      /* Disable profiling.  */
      int count;

      if (profile_thread != MACH_PORT_NULL)
       __thread_suspend (profile_thread);

      /* Fetch the last set of samples */
      if (sample_scale)
       fetch_samples ();

      err = __task_disable_pc_sampling (__mach_task_self (), &count);
      sample_scale = 0;
      seqno = 0;
    }
  else
    err = update_waiter (sample_buffer, size, offset, scale);

  __spin_unlock (&lock);

  return err ? __hurd_fail (err) : 0;
}

Here is the call graph for this function:

static kern_return_t profil_task_get_sampled_pcs ( mach_port_t  ,
sampled_pc_seqno_t *  ,
sampled_pc_array_t  ,
mach_msg_type_number_t *   
) [static]

Here is the caller graph for this function:

static void profile_waiter ( void  ) [static]

Definition at line 181 of file profil.c.

{
  mach_msg_header_t msg;
  mach_port_t timeout_reply_port;

  profil_reply_port = __mach_reply_port ();
  timeout_reply_port = __mach_reply_port ();

  while (1)
    {
      __spin_lock (&lock);

      fetch_samples ();

      __spin_unlock (&lock);

      __mach_msg (&msg, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0, sizeof msg,
                timeout_reply_port, collector_timeout, MACH_PORT_NULL);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

text_set_element ( _hurd_fork_prepare_hook  ,
fork_profil_prepare   
)
text_set_element ( _hurd_fork_parent_hook  ,
fork_profil_parent   
)
text_set_element ( _hurd_fork_child_hook  ,
fork_profil_child   
)
static error_t update_waiter ( u_short sample_buffer,
size_t  size,
size_t  offset,
u_int  scale 
) [static]

Definition at line 61 of file profil.c.

{
  error_t err;

  if (profile_thread == MACH_PORT_NULL)
    {
      /* Set up the profiling collector thread.  */
      err = __thread_create (__mach_task_self (), &profile_thread);
      if (! err)
       err = __mach_setup_thread (__mach_task_self (), profile_thread,
                               &profile_waiter, NULL, NULL);
    }
  else
    err = 0;

  if (! err)
    {
      err = __task_enable_pc_sampling (__mach_task_self (), &profile_tick,
                                   SAMPLED_PC_PERIODIC);
      if (!err && sample_scale == 0)
       /* Profiling was not turned on, so the collector thread was
          suspended.  Resume it.  */
       err = __thread_resume (profile_thread);
      if (! err)
       {
         samples = sample_buffer;
         maxsamples = size / sizeof *sample_buffer;
         pc_offset = offset;
         sample_scale = scale;
         /* Calculate a good period for the collector thread.  From TICK
            and the kernel buffer size we get the length of time it takes
            to fill the buffer; translate that to milliseconds for
            mach_msg, and chop it in half for general lag factor.  */
         collector_timeout = MAX_PC_SAMPLES * profile_tick / 1000 / 2;
       }
    }

  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

weak_alias ( __profil  ,
profil   
)

Definition at line 138 of file profil.c.

{
  sampled_pc_t pc_samples[MAX_PC_SAMPLES];
  mach_msg_type_number_t nsamples, i;
  error_t err;

  nsamples = MAX_PC_SAMPLES;

  err = profil_task_get_sampled_pcs (__mach_task_self (), &seqno,
                                 pc_samples, &nsamples);
  if (err)
    {
      static error_t special_profil_failure;
      static volatile int a, b, c;

      special_profil_failure = err;
      a = 1;
      b = 0;
      while (1)
       c = a / b;
    }

  for (i = 0; i < nsamples; ++i)
    {
      /* Do arithmetic in long long to avoid overflow problems. */
      long long pc_difference = pc_samples[i].pc - pc_offset;
      size_t idx = ((pc_difference / 2) * sample_scale) / 65536;
      if (idx < maxsamples)
       ++samples[idx];
    }
}

Here is the call graph for this function:


Variable Documentation

mach_msg_timeout_t collector_timeout [static]

Definition at line 40 of file profil.c.

Definition at line 39 of file profil.c.

size_t maxsamples [static]

Definition at line 35 of file profil.c.

size_t pc_offset [static]

Definition at line 36 of file profil.c.

mach_port_t profil_reply_port [static]

Definition at line 44 of file profil.c.

thread_t profile_thread = MACH_PORT_NULL [static]

Definition at line 33 of file profil.c.

int profile_tick [static]

Definition at line 41 of file profil.c.

size_t sample_scale [static]

Definition at line 37 of file profil.c.

u_short* samples [static]

Definition at line 34 of file profil.c.

sampled_pc_seqno_t seqno [static]

Definition at line 38 of file profil.c.