#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
+#include <errno.h>
#include "stackstash.h"
#include "collector.h"
#define N_PAGES 32 /* Number of pages in the ringbuffer */
+#define N_WAKEUP_EVENTS 150
+
typedef struct counter_t counter_t;
typedef struct sample_event_t sample_event_t;
typedef struct mmap_event_t mmap_event_t;
tracker_t * tracker;
GTimeVal latest_reset;
+ int prev_samples;
int n_samples;
GList * counters;
gboolean skip_samples;
Collector *collector;
uint64_t head, tail;
- gboolean first;
collector = counter->collector;
- first = collector->n_samples == 0;
#if 0
int n_bytes = mask + 1;
#endif
skip_samples = in_dead_period (collector);
+
+#if 0
+ g_print ("n bytes %d\n", head - tail);
+#endif
while (head - tail >= sizeof (struct perf_event_header))
{
counter->mmap_page->data_tail = tail;
if (collector->callback)
- collector->callback (first, collector->data);
+ {
+ if (collector->n_samples - collector->prev_samples >= N_WAKEUP_EVENTS)
+ {
+ gboolean first_sample = collector->prev_samples == 0;
+
+ collector->callback (first_sample, collector->data);
+
+ collector->prev_samples = collector->n_samples;
+ }
+ }
}
/* FIXME: return proper errors */
* FIXME: consider using frequency instead
*/
attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_CALLCHAIN;
- attr.wakeup_events = 100000;
+ attr.wakeup_events = N_WAKEUP_EVENTS;
attr.disabled = TRUE;
attr.mmap = 1;
attr.comm = 1;
attr.task = 1;
- fd = sysprof_perf_counter_open (&attr, -1, cpu, -1, 0);
+ if ((fd = sysprof_perf_counter_open (&attr, -1, cpu, -1, 0)) < 0)
+ {
+ if (errno == ENODEV)
+ {
+ attr.type = PERF_TYPE_SOFTWARE;
+ attr.config = PERF_COUNT_SW_CPU_CLOCK;
+ attr.sample_period = 10000000;
+
+ fd = sysprof_perf_counter_open (&attr, -1, cpu, -1, 0);
+ }
+ }
if (fd < 0)
{
}
collector->n_samples = 0;
+ collector->prev_samples = 0;
g_get_current_time (&collector->latest_reset);
break;
case PERF_EVENT_LOST:
+ g_print ("lost event\n");
break;
case PERF_EVENT_COMM:
break;
case PERF_EVENT_THROTTLE:
+ g_print ("throttle\n");
break;
case PERF_EVENT_UNTHROTTLE:
+ g_print ("unthrottle\n");
break;
case PERF_EVENT_FORK:
break;
default:
- g_warning ("unknown event: %d (%d)\n", event->header.type, event->header.size);
+ g_warning ("unknown event: %d (%d)\n",
+ event->header.type, event->header.size);
break;
}