b1c3c3c4515532081b79d9b80d6fa0fb8e7b16c7
2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <lttng/ust-clock.h>
15 * For sake of example, transform time into a coarse clock (freq: 1KHz).
16 * Note that division can be slow on some architectures. Should be
17 * avoided. Use shift and multiplication instead. e.g.:
19 * Operation: / 1000000ULL
20 * 1/1000000ULL = .000001
21 * 2^19 < 1000000 < 2^20
22 * Add a 10 bits shift to increase accuracy:
23 * 2^(19+10) = 536870912
24 * x * 1 / 2^(19+10) ~= .000001
25 * 537 * 1 / 2^29 = .00000100024044513702
26 * 537 (multiplication factor) is between 2^9 and 2^10.
28 * In order not to overflow, first right shift by 10, multiply, and right
31 #define DIV_CLOCK_SHIFT1 10
32 #define DIV_CLOCK_MUL 537
33 #define DIV_CLOCK_SHIFT2 19
36 uint64_t plugin_read64(void)
40 clock_gettime(CLOCK_MONOTONIC
, &ts
);
42 * This is a rather dumb example, but it illustrates the plugin
43 * mechanism: we take the monotonic clock, and transform it into
44 * a very coarse clock, which increment only at 1KHz frequency.
46 return ((uint64_t) ts
.tv_sec
* 1000ULL)
47 + ((DIV_CLOCK_MUL
* ((uint64_t) ts
.tv_nsec
>> DIV_CLOCK_SHIFT1
))
52 uint64_t plugin_freq(void)
54 return 1000; /* 1KHz clock (very coarse!) */
58 int plugin_uuid(char *uuid
)
60 const char myuuid
[] = "123456789012345678901234567890123456";
63 * Should read some unique identifier for this clock shared
64 * across all components of the system using this clock for
67 memcpy(uuid
, myuuid
, LTTNG_UST_UUID_STR_LEN
);
72 const char *plugin_name(void)
74 return "my_example_clock";
78 const char *plugin_description(void)
80 return "Coarse monotonic clock at 1KHz";
83 void lttng_ust_clock_plugin_init(void)
87 ret
= lttng_ust_trace_clock_set_read64_cb(plugin_read64
);
89 fprintf(stderr
, "Error setting clock override read64 callback: %s\n",
93 ret
= lttng_ust_trace_clock_set_freq_cb(plugin_freq
);
95 fprintf(stderr
, "Error setting clock override freq callback: %s\n",
99 ret
= lttng_ust_trace_clock_set_uuid_cb(plugin_uuid
);
101 fprintf(stderr
, "Error setting clock override uuid callback: %s\n",
106 ret
= lttng_ust_trace_clock_set_name_cb(plugin_name
);
108 fprintf(stderr
, "Error setting clock override name callback: %s\n",
113 ret
= lttng_ust_trace_clock_set_description_cb(plugin_description
);
115 fprintf(stderr
, "Error setting clock override description callback: %s\n",
120 ret
= lttng_ust_enable_trace_clock_override();
122 fprintf(stderr
, "Error enabling clock override: %s\n",
This page took 0.048175 seconds and 3 git commands to generate.