Exemplo n.º 1
0
static void
sp_hostinfo_source_prepare (SpSource *source)
{
  SpHostinfoSource *self = (SpHostinfoSource *)source;
  SpCaptureCounter *counters;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));

  self->stat_fd = open ("/proc/stat", O_RDONLY);
  self->n_cpu = g_get_num_processors ();

  g_array_set_size (self->cpu_info, 0);

  counters = alloca (sizeof *counters * self->n_cpu * 2);

  for (guint i = 0; i < self->n_cpu; i++)
    {
      SpCaptureCounter *ctr = &counters[i*2];
      CpuInfo info = { 0 };

      /*
       * Request 2 counter values.
       * One for CPU and one for Frequency.
       */
      info.counter_base = sp_capture_writer_request_counter (self->writer, 2);

      /*
       * Define counters for capture file.
       */
      ctr->id = info.counter_base;
      ctr->type = SP_CAPTURE_COUNTER_DOUBLE;
      ctr->value.vdbl = 0;
      g_strlcpy (ctr->category, "CPU Percent", sizeof ctr->category);
      g_snprintf (ctr->name, sizeof ctr->name, "Total CPU %d", i);
      g_snprintf (ctr->description, sizeof ctr->description,
                  "Total CPU usage %d", i);

      ctr++;

      ctr->id = info.counter_base + 1;
      ctr->type = SP_CAPTURE_COUNTER_DOUBLE;
      ctr->value.vdbl = 0;
      g_strlcpy (ctr->category, "CPU Frequency", sizeof ctr->category);
      g_snprintf (ctr->name, sizeof ctr->name, "CPU %d", i);
      g_snprintf (ctr->description, sizeof ctr->description,
                  "Frequency of CPU %d", i);

      g_array_append_val (self->cpu_info, info);
    }

  sp_capture_writer_define_counters (self->writer,
                                     SP_CAPTURE_CURRENT_TIME,
                                     -1,
                                     getpid (),
                                     counters,
                                     self->n_cpu * 2);

  sp_source_emit_ready (SP_SOURCE (self));
}
Exemplo n.º 2
0
static void
sp_hostinfo_source_start (SpSource *source)
{
  SpHostinfoSource *self = (SpHostinfoSource *)source;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));

  self->handler = g_timeout_add (250, collect_hostinfo_cb, self);
}
Exemplo n.º 3
0
static void
sp_hostinfo_source_start (SpSource *source)
{
  SpHostinfoSource *self = (SpHostinfoSource *)source;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));

  /* 20 samples per second */
  self->handler = g_timeout_add (1000/20, collect_hostinfo_cb, self);
}
Exemplo n.º 4
0
static void
sp_hostinfo_source_set_writer (SpSource        *source,
                               SpCaptureWriter *writer)
{
  SpHostinfoSource *self = (SpHostinfoSource *)source;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));
  g_assert (writer != NULL);

  g_clear_pointer (&self->writer, sp_capture_writer_unref);
  self->writer = sp_capture_writer_ref (writer);
}
Exemplo n.º 5
0
static gboolean
collect_hostinfo_cb (gpointer data)
{
  SpHostinfoSource *self = data;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));

  poll_cpu (self);
  publish_cpu (self);

  return G_SOURCE_CONTINUE;
}
Exemplo n.º 6
0
static void
sp_hostinfo_source_stop (SpSource *source)
{
  SpHostinfoSource *self = (SpHostinfoSource *)source;

  g_assert (SP_IS_HOSTINFO_SOURCE (self));

  g_source_remove (self->handler);
  self->handler = 0;

  sp_source_emit_finished (SP_SOURCE (self));
}