[sysprof] capture: add API to request a counter id



commit 61be0a04555e3f177ec93b69a8ff95724cbd6425
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 19 15:09:52 2020 -0700

    capture: add API to request a counter id

 src/libsysprof-capture/sysprof-collector.c | 18 ++++++++
 src/libsysprof-capture/sysprof-collector.h | 74 +++++++++++++++---------------
 2 files changed, 56 insertions(+), 36 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c
index b77811cf..23a3c105 100644
--- a/src/libsysprof-capture/sysprof-collector.c
+++ b/src/libsysprof-capture/sysprof-collector.c
@@ -95,6 +95,7 @@ typedef struct
   bool is_shared;
   int tid;
   int pid;
+  int next_counter_id;
 } SysprofCollector;
 
 #define COLLECTOR_INVALID ((void *)&invalid)
@@ -420,6 +421,7 @@ sysprof_collector_get (void)
 #else
     self->tid = self->pid;
 #endif
+    self->next_counter_id = 1;
 
     pthread_mutex_lock (&control_fd_lock);
 
@@ -845,3 +847,19 @@ sysprof_collector_set_counters (const unsigned int               *counters_ids,
       }
   } 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;
+}
diff --git a/src/libsysprof-capture/sysprof-collector.h b/src/libsysprof-capture/sysprof-collector.h
index 53a7beec..f989f08f 100644
--- a/src/libsysprof-capture/sysprof-collector.h
+++ b/src/libsysprof-capture/sysprof-collector.h
@@ -64,50 +64,52 @@
 SYSPROF_BEGIN_DECLS
 
 SYSPROF_AVAILABLE_IN_3_36
-void sysprof_collector_init            (void);
+void         sysprof_collector_init            (void);
 SYSPROF_AVAILABLE_IN_3_36
-void sysprof_collector_allocate        (SysprofCaptureAddress             alloc_addr,
-                                        int64_t                           alloc_size,
-                                        SysprofBacktraceFunc              backtrace_func,
-                                        void                             *backtrace_data);
+void         sysprof_collector_allocate        (SysprofCaptureAddress             alloc_addr,
+                                                int64_t                           alloc_size,
+                                                SysprofBacktraceFunc              backtrace_func,
+                                                void                             *backtrace_data);
 SYSPROF_AVAILABLE_IN_3_36
-void sysprof_collector_sample          (SysprofBacktraceFunc              backtrace_func,
-                                        void                             *backtrace_data);
+void         sysprof_collector_sample          (SysprofBacktraceFunc              backtrace_func,
+                                                void                             *backtrace_data);
 SYSPROF_AVAILABLE_IN_3_36
-void sysprof_collector_mark            (int64_t                           time,
-                                        int64_t                           duration,
-                                        const char                       *group,
-                                        const char                       *mark,
-                                        const char                       *message);
+void         sysprof_collector_mark            (int64_t                           time,
+                                                int64_t                           duration,
+                                                const char                       *group,
+                                                const char                       *mark,
+                                                const char                       *message);
 SYSPROF_AVAILABLE_IN_3_38
-void sysprof_collector_mark_printf     (int64_t                           time,
-                                        int64_t                           duration,
-                                        const char                       *group,
-                                        const char                       *mark,
-                                        const char                       *message_format,
-                                        ...) SYSPROF_PRINTF(5, 6);
+void         sysprof_collector_mark_printf     (int64_t                           time,
+                                                int64_t                           duration,
+                                                const char                       *group,
+                                                const char                       *mark,
+                                                const char                       *message_format,
+                                                ...) SYSPROF_PRINTF(5, 6);
 SYSPROF_AVAILABLE_IN_3_38
-void sysprof_collector_mark_vprintf    (int64_t                           time,
-                                        int64_t                           duration,
-                                        const char                       *group,
-                                        const char                       *mark,
-                                        const char                       *message_format,
-                                        va_list                           args) SYSPROF_PRINTF(5, 0);
+void         sysprof_collector_mark_vprintf    (int64_t                           time,
+                                                int64_t                           duration,
+                                                const char                       *group,
+                                                const char                       *mark,
+                                                const char                       *message_format,
+                                                va_list                           args) SYSPROF_PRINTF(5, 0);
 SYSPROF_AVAILABLE_IN_3_36
-void sysprof_collector_log             (int                               severity,
-                                        const char                       *domain,
-                                        const char                       *message);
+void         sysprof_collector_log             (int                               severity,
+                                                const char                       *domain,
+                                                const char                       *message);
 SYSPROF_AVAILABLE_IN_3_38
-void sysprof_collector_log_printf      (int                               severity,
-                                        const char                       *domain,
-                                        const char                       *format,
-                                        ...) SYSPROF_PRINTF (3, 4);
+void         sysprof_collector_log_printf      (int                               severity,
+                                                const char                       *domain,
+                                                const char                       *format,
+                                                ...) SYSPROF_PRINTF (3, 4);
 SYSPROF_AVAILABLE_IN_3_38
-void sysprof_collector_define_counters (const SysprofCaptureCounter      *counters,
-                                        unsigned int                      n_counters);
+unsigned int sysprof_collector_request_counter (unsigned int                      n_counters);
 SYSPROF_AVAILABLE_IN_3_38
-void sysprof_collector_set_counters    (const unsigned int               *counters_ids,
-                                        const SysprofCaptureCounterValue *values,
-                                        unsigned int                      n_counters);
+void         sysprof_collector_define_counters (const SysprofCaptureCounter      *counters,
+                                                unsigned int                      n_counters);
+SYSPROF_AVAILABLE_IN_3_38
+void         sysprof_collector_set_counters    (const unsigned int               *counters_ids,
+                                                const SysprofCaptureCounterValue *values,
+                                                unsigned int                      n_counters);
 
 SYSPROF_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]