1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <stdio.h>
7 #include <syslog.h>
8 #include <unistd.h>
9
10 #define METRICS_CLIENT "metrics_client"
11
cras_metrics_log_event(const char * event)12 void cras_metrics_log_event(const char *event)
13 {
14 syslog(LOG_DEBUG, "Log event: %s", event);
15 if (!fork()) {
16 const char *argv[] = {METRICS_CLIENT, "-v", event, NULL} ;
17 execvp(argv[0], (char * const *)argv);
18 _exit(1);
19 }
20 }
21
cras_metrics_log_histogram(const char * name,int sample,int min,int max,int nbuckets)22 void cras_metrics_log_histogram(const char *name, int sample, int min,
23 int max, int nbuckets)
24 {
25 if (!fork()) {
26 char tmp[4][16];
27 snprintf(tmp[0], 16, "%d", sample);
28 snprintf(tmp[1], 16, "%d", min);
29 snprintf(tmp[2], 16, "%d", max);
30 snprintf(tmp[3], 16, "%d", nbuckets);
31 const char *argv[] = {METRICS_CLIENT, name, tmp[0], tmp[1],
32 tmp[2], tmp[3], NULL};
33 execvp(argv[0], (char * const *)argv);
34 _exit(1);
35 }
36 }
37