capture: add API to request a counter id

This commit is contained in:
Christian Hergert
2020-08-19 15:09:52 -07:00
parent b913de8882
commit 61be0a0455
2 changed files with 56 additions and 36 deletions

View File

@ -95,6 +95,7 @@ typedef struct
bool is_shared; bool is_shared;
int tid; int tid;
int pid; int pid;
int next_counter_id;
} SysprofCollector; } SysprofCollector;
#define COLLECTOR_INVALID ((void *)&invalid) #define COLLECTOR_INVALID ((void *)&invalid)
@ -420,6 +421,7 @@ sysprof_collector_get (void)
#else #else
self->tid = self->pid; self->tid = self->pid;
#endif #endif
self->next_counter_id = 1;
pthread_mutex_lock (&control_fd_lock); pthread_mutex_lock (&control_fd_lock);
@ -845,3 +847,19 @@ sysprof_collector_set_counters (const unsigned int *counters_ids,
} }
} COLLECTOR_END; } COLLECTOR_END;
} }
unsigned int
sysprof_collector_request_counter (unsigned int n_counters)
{
unsigned int ret = 0;
if (n_counters == 0)
return 0;
COLLECTOR_BEGIN {
ret = collector->next_counter_id;
((SysprofCollector *)collector)->next_counter_id += n_counters;
} COLLECTOR_END;
return ret;
}

View File

@ -103,6 +103,8 @@ void sysprof_collector_log_printf (int severi
const char *format, const char *format,
...) SYSPROF_PRINTF (3, 4); ...) SYSPROF_PRINTF (3, 4);
SYSPROF_AVAILABLE_IN_3_38 SYSPROF_AVAILABLE_IN_3_38
unsigned int sysprof_collector_request_counter (unsigned int n_counters);
SYSPROF_AVAILABLE_IN_3_38
void sysprof_collector_define_counters (const SysprofCaptureCounter *counters, void sysprof_collector_define_counters (const SysprofCaptureCounter *counters,
unsigned int n_counters); unsigned int n_counters);
SYSPROF_AVAILABLE_IN_3_38 SYSPROF_AVAILABLE_IN_3_38