All of lore.kernel.org
 help / color / mirror / Atom feed
* [Babeltrace PATCH] Add new option --clock-offset-ns
@ 2013-04-12  5:52 Ikaheimonen, JP
  0 siblings, 0 replies; 4+ messages in thread
From: Ikaheimonen, JP @ 2013-04-12  5:52 UTC (permalink / raw)
  To: lttng-dev


Add a new option --clock-offset-ns. It requires a parameter
that specifies a clock offset (in nanoseconds) that is added
to each timestamp.

This works exactly as the option --clock-offset, except that
the value is given in nanoseconds instead of full seconds.

The two options --clock-offset and --clock-offset-ns are
compatible with each other, and it's possible to give both.
For example, having the options

--clock-offset 2 --clock-offset-ns 1000000

means that 2.001 seconds is added to each timestamp.
---
 converter/babeltrace.c                   | 26 ++++++++++++++++++++++++++
 formats/ctf/ctf.c                        |  4 ++++
 include/babeltrace/babeltrace-internal.h |  1 +
 3 files changed, 31 insertions(+)

diff --git a/converter/babeltrace.c b/converter/babeltrace.c
index 83f300c..bfdfc47 100644
--- a/converter/babeltrace.c
+++ b/converter/babeltrace.c
@@ -92,6 +92,7 @@ enum {
 	OPT_FIELDS,
 	OPT_NO_DELTA,
 	OPT_CLOCK_OFFSET,
+	OPT_CLOCK_OFFSET_NS,
 	OPT_CLOCK_CYCLES,
 	OPT_CLOCK_SECONDS,
 	OPT_CLOCK_DATE,
@@ -120,6 +121,7 @@ static struct poptOption long_options[] = {
 	{ "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
 	{ "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
 	{ "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
+	{ "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
 	{ "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
 	{ "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
 	{ "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
@@ -163,6 +165,7 @@ static void usage(FILE *fp)
 	fprintf(fp, "                                     (default: trace:hostname,trace:procname,trace:vpid)\n");
 	fprintf(fp, "      --clock-cycles             Timestamp in cycles\n");
 	fprintf(fp, "      --clock-offset seconds     Clock offset in seconds\n");
+	fprintf(fp, "      --clock-offset-ns ns       Clock offset in nanoseconds\n");
 	fprintf(fp, "      --clock-seconds            Print the timestamps as [sec.ns]\n");
 	fprintf(fp, "                                 (default is: [hh:mm:ss.ns])\n");
 	fprintf(fp, "      --clock-date               Print clock date\n");
@@ -356,6 +359,29 @@ static int parse_options(int argc, char **argv)
 		case OPT_CLOCK_SECONDS:
 			opt_clock_seconds = 1;
 			break;
+		case OPT_CLOCK_OFFSET_NS:
+		{
+			char *str;
+			char *endptr;
+
+			str = (char *) poptGetOptArg(pc);
+			if (!str) {
+				fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
+				ret = -EINVAL;
+				goto end;
+			}
+			errno = 0;
+			opt_clock_offset_ns = strtoull(str, &endptr, 0);
+			if (*endptr != '\0' || str == endptr || errno != 0) {
+				fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
+				ret = -EINVAL;
+				free(str);
+				goto end;
+			}
+			free(str);
+			break;
+		}
+
 		case OPT_CLOCK_DATE:
 			opt_clock_date = 1;
 			break;
diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
index 5a51495..4f320a6 100644
--- a/formats/ctf/ctf.c
+++ b/formats/ctf/ctf.c
@@ -72,6 +72,7 @@ int opt_clock_cycles,
 	opt_clock_gmt;
 
 uint64_t opt_clock_offset;
+uint64_t opt_clock_offset_ns;
 
 extern int yydebug;
 
@@ -316,6 +317,9 @@ void ctf_print_timestamp_real(FILE *fp,
 
 	ts_nsec = timestamp;
 
+	/* Add command-line offset in ns*/
+        ts_nsec += opt_clock_offset_ns;
+
 	/* Add command-line offset */
 	ts_sec += opt_clock_offset;
 
diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h
index 6219b3a..81ea9b9 100644
--- a/include/babeltrace/babeltrace-internal.h
+++ b/include/babeltrace/babeltrace-internal.h
@@ -85,5 +85,6 @@ extern int opt_all_field_names,
 	opt_clock_force_correlate;
 
 extern uint64_t opt_clock_offset;
+extern uint64_t opt_clock_offset_ns;
 
 #endif
-- 
1.8.1.msysgit.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Babeltrace PATCH] Add new option --clock-offset-ns
       [not found] <009B25148989C6458484484699278506E5371E30@EU-MBX-03.mgc.mentorg.com>
  2013-04-12 13:21 ` Mathieu Desnoyers
       [not found] ` <20130412132158.GA27890@Krystal>
@ 2013-05-02 14:21 ` Mathieu Desnoyers
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers @ 2013-05-02 14:21 UTC (permalink / raw)
  To: Ikaheimonen, JP; +Cc: lttng-dev

merged, thanks!

Mathieu

* Ikaheimonen, JP (jp_ikaheimonen@mentor.com) wrote:
> 
> Add a new option --clock-offset-ns. It requires a parameter
> that specifies a clock offset (in nanoseconds) that is added
> to each timestamp.
> 
> This works exactly as the option --clock-offset, except that
> the value is given in nanoseconds instead of full seconds.
> 
> The two options --clock-offset and --clock-offset-ns are
> compatible with each other, and it's possible to give both.
> For example, having the options
> 
> --clock-offset 2 --clock-offset-ns 1000000
> 
> means that 2.001 seconds is added to each timestamp.
> ---
>  converter/babeltrace.c                   | 26 ++++++++++++++++++++++++++
>  formats/ctf/ctf.c                        |  4 ++++
>  include/babeltrace/babeltrace-internal.h |  1 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/converter/babeltrace.c b/converter/babeltrace.c
> index 83f300c..bfdfc47 100644
> --- a/converter/babeltrace.c
> +++ b/converter/babeltrace.c
> @@ -92,6 +92,7 @@ enum {
>  	OPT_FIELDS,
>  	OPT_NO_DELTA,
>  	OPT_CLOCK_OFFSET,
> +	OPT_CLOCK_OFFSET_NS,
>  	OPT_CLOCK_CYCLES,
>  	OPT_CLOCK_SECONDS,
>  	OPT_CLOCK_DATE,
> @@ -120,6 +121,7 @@ static struct poptOption long_options[] = {
>  	{ "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
>  	{ "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
>  	{ "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
> +	{ "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
>  	{ "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
>  	{ "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
>  	{ "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
> @@ -163,6 +165,7 @@ static void usage(FILE *fp)
>  	fprintf(fp, "                                     (default: trace:hostname,trace:procname,trace:vpid)\n");
>  	fprintf(fp, "      --clock-cycles             Timestamp in cycles\n");
>  	fprintf(fp, "      --clock-offset seconds     Clock offset in seconds\n");
> +	fprintf(fp, "      --clock-offset-ns ns       Clock offset in nanoseconds\n");
>  	fprintf(fp, "      --clock-seconds            Print the timestamps as [sec.ns]\n");
>  	fprintf(fp, "                                 (default is: [hh:mm:ss.ns])\n");
>  	fprintf(fp, "      --clock-date               Print clock date\n");
> @@ -356,6 +359,29 @@ static int parse_options(int argc, char **argv)
>  		case OPT_CLOCK_SECONDS:
>  			opt_clock_seconds = 1;
>  			break;
> +		case OPT_CLOCK_OFFSET_NS:
> +		{
> +			char *str;
> +			char *endptr;
> +
> +			str = (char *) poptGetOptArg(pc);
> +			if (!str) {
> +				fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
> +				ret = -EINVAL;
> +				goto end;
> +			}
> +			errno = 0;
> +			opt_clock_offset_ns = strtoull(str, &endptr, 0);
> +			if (*endptr != '\0' || str == endptr || errno != 0) {
> +				fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
> +				ret = -EINVAL;
> +				free(str);
> +				goto end;
> +			}
> +			free(str);
> +			break;
> +		}
> +
>  		case OPT_CLOCK_DATE:
>  			opt_clock_date = 1;
>  			break;
> diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
> index 5a51495..4f320a6 100644
> --- a/formats/ctf/ctf.c
> +++ b/formats/ctf/ctf.c
> @@ -72,6 +72,7 @@ int opt_clock_cycles,
>  	opt_clock_gmt;
>  
>  uint64_t opt_clock_offset;
> +uint64_t opt_clock_offset_ns;
>  
>  extern int yydebug;
>  
> @@ -316,6 +317,9 @@ void ctf_print_timestamp_real(FILE *fp,
>  
>  	ts_nsec = timestamp;
>  
> +	/* Add command-line offset in ns*/
> +        ts_nsec += opt_clock_offset_ns;
> +
>  	/* Add command-line offset */
>  	ts_sec += opt_clock_offset;
>  
> diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h
> index 6219b3a..81ea9b9 100644
> --- a/include/babeltrace/babeltrace-internal.h
> +++ b/include/babeltrace/babeltrace-internal.h
> @@ -85,5 +85,6 @@ extern int opt_all_field_names,
>  	opt_clock_force_correlate;
>  
>  extern uint64_t opt_clock_offset;
> +extern uint64_t opt_clock_offset_ns;
>  
>  #endif
> -- 
> 1.8.1.msysgit.1
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Babeltrace PATCH] Add new option --clock-offset-ns
       [not found] ` <20130412132158.GA27890@Krystal>
@ 2013-04-15  5:28   ` Ikaheimonen, JP
  0 siblings, 0 replies; 4+ messages in thread
From: Ikaheimonen, JP @ 2013-04-15  5:28 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

Hi Mathieu,

you ponder:
> +			opt_clock_offset_ns = strtoull(str, &endptr, 0);
> +			if (*endptr != '\0' || str == endptr || errno != 0) {
>Why test *endptr != '\0' and str == endptr ?

This check has been copied verbatim from the similar handler for option OPT_CLOCK_ OFFSET.

To me, the check for *endptr != '\0' has some value. stroull(3) will report success if the argument
starts with a valid number, and the test makes sure that the entire argument was used in converting
the number (that is, there are no trailing bad characters).

Likewise, the check str==endptr checks if any conversion occurred at all,
although this should be covered by the error case of EINVAL.
However, the manual only treats this error case as a possibility ('may return'), 
so the check is necessary to make sure of the fact in all library implementations.

Cheers,

JP Ikaheimonen | SW Development Engineer http://go.mentor.com/sourceryanalyzer

Mentor Embedded(tm) | Nucleus(r) | Linux(r) | Android(tm) | Services | UI | Multi-OS

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Babeltrace PATCH] Add new option --clock-offset-ns
       [not found] <009B25148989C6458484484699278506E5371E30@EU-MBX-03.mgc.mentorg.com>
@ 2013-04-12 13:21 ` Mathieu Desnoyers
       [not found] ` <20130412132158.GA27890@Krystal>
  2013-05-02 14:21 ` Mathieu Desnoyers
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers @ 2013-04-12 13:21 UTC (permalink / raw)
  To: Ikaheimonen, JP; +Cc: lttng-dev

* Ikaheimonen, JP (jp_ikaheimonen@mentor.com) wrote:
> 
> Add a new option --clock-offset-ns. It requires a parameter
> that specifies a clock offset (in nanoseconds) that is added
> to each timestamp.
> 
> This works exactly as the option --clock-offset, except that
> the value is given in nanoseconds instead of full seconds.
> 
> The two options --clock-offset and --clock-offset-ns are
> compatible with each other, and it's possible to give both.
> For example, having the options

Sounds like a nice feature. One comment below,

> 
> --clock-offset 2 --clock-offset-ns 1000000
> 
> means that 2.001 seconds is added to each timestamp.
> ---
>  converter/babeltrace.c                   | 26 ++++++++++++++++++++++++++
>  formats/ctf/ctf.c                        |  4 ++++
>  include/babeltrace/babeltrace-internal.h |  1 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/converter/babeltrace.c b/converter/babeltrace.c
> index 83f300c..bfdfc47 100644
> --- a/converter/babeltrace.c
> +++ b/converter/babeltrace.c
> @@ -92,6 +92,7 @@ enum {
>  	OPT_FIELDS,
>  	OPT_NO_DELTA,
>  	OPT_CLOCK_OFFSET,
> +	OPT_CLOCK_OFFSET_NS,
>  	OPT_CLOCK_CYCLES,
>  	OPT_CLOCK_SECONDS,
>  	OPT_CLOCK_DATE,
> @@ -120,6 +121,7 @@ static struct poptOption long_options[] = {
>  	{ "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
>  	{ "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
>  	{ "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
> +	{ "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
>  	{ "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
>  	{ "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
>  	{ "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
> @@ -163,6 +165,7 @@ static void usage(FILE *fp)
>  	fprintf(fp, "                                     (default: trace:hostname,trace:procname,trace:vpid)\n");
>  	fprintf(fp, "      --clock-cycles             Timestamp in cycles\n");
>  	fprintf(fp, "      --clock-offset seconds     Clock offset in seconds\n");
> +	fprintf(fp, "      --clock-offset-ns ns       Clock offset in nanoseconds\n");
>  	fprintf(fp, "      --clock-seconds            Print the timestamps as [sec.ns]\n");
>  	fprintf(fp, "                                 (default is: [hh:mm:ss.ns])\n");
>  	fprintf(fp, "      --clock-date               Print clock date\n");
> @@ -356,6 +359,29 @@ static int parse_options(int argc, char **argv)
>  		case OPT_CLOCK_SECONDS:
>  			opt_clock_seconds = 1;
>  			break;
> +		case OPT_CLOCK_OFFSET_NS:
> +		{
> +			char *str;
> +			char *endptr;
> +
> +			str = (char *) poptGetOptArg(pc);
> +			if (!str) {
> +				fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
> +				ret = -EINVAL;
> +				goto end;
> +			}
> +			errno = 0;
> +			opt_clock_offset_ns = strtoull(str, &endptr, 0);
> +			if (*endptr != '\0' || str == endptr || errno != 0) {

Why test *endptr != '\0' and str == endptr ?

From my understanding of strtoull(3), just:

errno = 0;
opt_clock_offset_ns = strtoull(str, NULL, 0);
if (errno != 0) {
        handle error...
}

should be enough.. ? If not, I'd really like to know what I am missing.

Thanks,

Mathieu

> +				fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
> +				ret = -EINVAL;
> +				free(str);
> +				goto end;
> +			}
> +			free(str);
> +			break;
> +		}
> +
>  		case OPT_CLOCK_DATE:
>  			opt_clock_date = 1;
>  			break;
> diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
> index 5a51495..4f320a6 100644
> --- a/formats/ctf/ctf.c
> +++ b/formats/ctf/ctf.c
> @@ -72,6 +72,7 @@ int opt_clock_cycles,
>  	opt_clock_gmt;
>  
>  uint64_t opt_clock_offset;
> +uint64_t opt_clock_offset_ns;
>  
>  extern int yydebug;
>  
> @@ -316,6 +317,9 @@ void ctf_print_timestamp_real(FILE *fp,
>  
>  	ts_nsec = timestamp;
>  
> +	/* Add command-line offset in ns*/
> +        ts_nsec += opt_clock_offset_ns;
> +
>  	/* Add command-line offset */
>  	ts_sec += opt_clock_offset;
>  
> diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h
> index 6219b3a..81ea9b9 100644
> --- a/include/babeltrace/babeltrace-internal.h
> +++ b/include/babeltrace/babeltrace-internal.h
> @@ -85,5 +85,6 @@ extern int opt_all_field_names,
>  	opt_clock_force_correlate;
>  
>  extern uint64_t opt_clock_offset;
> +extern uint64_t opt_clock_offset_ns;
>  
>  #endif
> -- 
> 1.8.1.msysgit.1
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-02 14:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-12  5:52 [Babeltrace PATCH] Add new option --clock-offset-ns Ikaheimonen, JP
     [not found] <009B25148989C6458484484699278506E5371E30@EU-MBX-03.mgc.mentorg.com>
2013-04-12 13:21 ` Mathieu Desnoyers
     [not found] ` <20130412132158.GA27890@Krystal>
2013-04-15  5:28   ` Ikaheimonen, JP
2013-05-02 14:21 ` Mathieu Desnoyers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.