Support standard timestamp formats for begin/end
[babeltrace.git] / plugins / trimmer / iterator.c
index 0cdd69f254ba83817b69b41e1c5ad724e425ce29..68105b9f27ae85f4e307c8a56af165f6d0691763 100644 (file)
@@ -129,6 +129,64 @@ end:
        return bt_get(trim_it->current_notification);
 }
 
+static
+int update_lazy_bound(struct trimmer_bound *bound, const char *name,
+               int64_t ts)
+{
+       struct tm tm;
+       int64_t value;
+       time_t timeval;
+
+       if (!bound->lazy) {
+               return 0;
+       }
+       tm.tm_isdst = -1;
+       timeval = ts / NSEC_PER_SEC;
+
+       if (bound->lazy_values.gmt) {
+               /* Get day, month, year. */
+               if (!gmtime_r(&timeval, &tm)) {
+                       printf_error("Failure in gmtime_r()\n");
+                       goto error;
+               }
+               tm.tm_sec = bound->lazy_values.ss;
+               tm.tm_min = bound->lazy_values.mm;
+               tm.tm_hour = bound->lazy_values.hh;
+               timeval = timegm(&tm);
+               if (timeval < 0) {
+                       printf_error("Failure in timegm(), incorrectly formatted %s timestamp\n",
+                               name);
+                       goto error;
+               }
+       } else {
+               /* Get day, month, year. */
+               if (!localtime_r(&timeval, &tm)) {
+                       printf_error("Failure in localtime_r()\n");
+                       goto error;
+               }
+               tm.tm_sec = bound->lazy_values.ss;
+               tm.tm_min = bound->lazy_values.mm;
+               tm.tm_hour = bound->lazy_values.hh;
+               timeval = mktime(&tm);
+               if (timeval < 0) {
+                       printf_error("Failure in mktime(), incorrectly formatted %s timestamp\n",
+                               name);
+                       goto error;
+               }
+       }
+       value = (int64_t) timeval;
+       value *= NSEC_PER_SEC;
+       value += bound->lazy_values.ns;
+       bound->value = value;
+       bound->set = true;
+       bound->lazy = false;
+       return 0;
+
+error:
+       bound->lazy = false;
+       return -1;
+}
+
 static
 bool evaluate_event_notification(struct bt_notification *notification,
                struct trimmer_bound *begin, struct trimmer_bound *end)
@@ -173,7 +231,12 @@ bool evaluate_event_notification(struct bt_notification *notification,
                printf_error("Failed to retrieve clock value timestamp\n");
                goto end;
        }
-
+       if (update_lazy_bound(begin, "begin", ts)) {
+               goto end;
+       }
+       if (update_lazy_bound(end, "end", ts)) {
+               goto end;
+       }
        if (begin->set && ts < begin->value) {
                in_range = false;
        }
This page took 0.023631 seconds and 4 git commands to generate.