[igt-dev] [PATCH i-g-t 2/5] lib: Export igt_gettime and igt_time_elapsed

Petri Latvala petri.latvala at intel.com
Wed Jun 13 10:07:36 UTC 2018


Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Tomi Sarvela <tomi.p.sarvela at intel.com>
Cc: Martin Peres <martin.peres at linux.intel.com>
---
 lib/igt_core.c | 23 +++++++++++------------
 lib/igt_core.h | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index fe163bd8..bc9b8c84 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -407,9 +407,8 @@ void igt_kmsg(const char *format, ...)
 
 #define time_valid(ts) ((ts)->tv_sec || (ts)->tv_nsec)
 
-static double
-time_elapsed(struct timespec *then,
-	     struct timespec* now)
+double igt_time_elapsed(struct timespec *then,
+			struct timespec *now)
 {
 	double elapsed = -1.;
 
@@ -421,7 +420,7 @@ time_elapsed(struct timespec *then,
 	return elapsed;
 }
 
-static int gettime(struct timespec *ts)
+int igt_gettime(struct timespec *ts)
 {
 	memset(ts, 0, sizeof(*ts));
 	errno = 0;
@@ -454,7 +453,7 @@ uint64_t igt_nsec_elapsed(struct timespec *start)
 {
 	struct timespec now;
 
-	gettime(&now);
+	igt_gettime(&now);
 	if ((start->tv_sec | start->tv_nsec) == 0) {
 		*start = now;
 		return 0;
@@ -819,7 +818,7 @@ out:
 	igt_install_exit_handler(common_exit_handler);
 
 	if (!test_with_subtests)
-		gettime(&subtest_time);
+		igt_gettime(&subtest_time);
 
 	for (i = 0; (optind + i) < *argc; i++)
 		argv[i + 1] = argv[optind + i];
@@ -948,7 +947,7 @@ bool __igt_run_subtest(const char *subtest_name)
 
 	_igt_log_buffer_reset();
 
-	gettime(&subtest_time);
+	igt_gettime(&subtest_time);
 	return (in_subtest = subtest_name);
 }
 
@@ -993,15 +992,15 @@ static void exit_subtest(const char *result)
 {
 	struct timespec now;
 
-	gettime(&now);
+	igt_gettime(&now);
 	igt_info("%sSubtest %s: %s (%.3fs)%s\n",
 		 (!__igt_plain_output) ? "\x1b[1m" : "",
-		 in_subtest, result, time_elapsed(&subtest_time, &now),
+		 in_subtest, result, igt_time_elapsed(&subtest_time, &now),
 		 (!__igt_plain_output) ? "\x1b[0m" : "");
 	fflush(stdout);
 	if (stderr_needs_sentinel)
 		fprintf(stderr, "Subtest %s: %s (%.3fs)\n",
-			in_subtest, result, time_elapsed(&subtest_time, &now));
+			in_subtest, result, igt_time_elapsed(&subtest_time, &now));
 
 	igt_terminate_spin_batches();
 
@@ -1488,7 +1487,7 @@ void igt_exit(void)
 		struct timespec now;
 		const char *result;
 
-		gettime(&now);
+		igt_gettime(&now);
 
 		switch (igt_exitcode) {
 			case IGT_EXIT_SUCCESS:
@@ -1505,7 +1504,7 @@ void igt_exit(void)
 		}
 
 		printf("%s (%.3fs)\n",
-		       result, time_elapsed(&subtest_time, &now));
+		       result, igt_time_elapsed(&subtest_time, &now));
 	}
 
 	exit(igt_exitcode);
diff --git a/lib/igt_core.h b/lib/igt_core.h
index a73b0649..e06cc7ff 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -928,6 +928,26 @@ extern enum igt_log_level igt_log_level;
 void igt_set_timeout(unsigned int seconds,
 		     const char *op);
 
+/**
+ * igt_gettime:
+ * @ts: current monotonic clock reading
+ *
+ * Reports the current time in the monotonic clock.
+ * Returns: 0 on success, -errno on failure.
+ */
+int igt_gettime(struct timespec *ts);
+
+/**
+ * igt_time_elapsed:
+ * @then: Earlier timestamp
+ * @now: Later timestamp
+ *
+ * Returns: Time between two timestamps in seconds, as a floating
+ * point number.
+ */
+double igt_time_elapsed(struct timespec *then,
+			struct timespec *now);
+
 /**
  * igt_nsec_elapsed:
  * @start: measure from this point in time
-- 
2.14.1



More information about the igt-dev mailing list