[igt-dev] [PATCH i-g-t 1/1] runner: Add time_elapsed field to results
Petri Latvala
petri.latvala at intel.com
Thu Sep 27 13:11:42 UTC 2018
When starting a test run, drop a timestamp file. Do the same when
ending a run. Slap those timestamps directly into the time_elapsed
field in results.json.
Using timestamps instead of measuring actual elapsed time goes against
the naming of the field, but the name is chosen by piglit. Even though
piglit itself uses timestamps.
Corner cases:
On incomplete test runs, the end timestamp will be missing. The
time_elapsed field will only have the start timestamp. This matches
piglit behaviour exactly.
On incomplete but resumed test runs, the end timestamp will be the
time when the resume finishes. Piglit doesn't do this, and instead
leaves the end timestamp missing. Discussing which behaviour is better
is left as an exercise to the readers.
Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Tomi Sarvela <tomi.p.sarvela at intel.com>
---
runner/executor.c | 33 ++++++++++++++++++++++++++++++---
runner/resultgen.c | 27 +++++++++++++++++++++------
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/runner/executor.c b/runner/executor.c
index d0539aa1..4552b02c 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -9,6 +9,7 @@
#include <sys/select.h>
#include <sys/signalfd.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
@@ -860,7 +861,9 @@ static bool clear_old_results(char *path)
return false;
}
- if (unlinkat(dirfd, "uname.txt", 0) && errno != ENOENT) {
+ if (remove_file(dirfd, "uname.txt") ||
+ remove_file(dirfd, "starttime.txt") ||
+ remove_file(dirfd, "endtime.txt")) {
close(dirfd);
fprintf(stderr, "Error clearing old results: %s\n", strerror(errno));
return false;
@@ -892,6 +895,15 @@ static bool clear_old_results(char *path)
return true;
}
+static double timeofday_double()
+{
+ struct timeval tv;
+
+ if (!gettimeofday(&tv, NULL))
+ return tv.tv_sec + tv.tv_usec / 1000000.0;
+ return 0.0;
+}
+
bool initialize_execute_state_from_resume(int dirfd,
struct execute_state *state,
struct settings *settings,
@@ -973,7 +985,7 @@ bool execute(struct execute_state *state,
struct job_list *job_list)
{
struct utsname unamebuf;
- int resdirfd, testdirfd, unamefd;
+ int resdirfd, testdirfd, unamefd, timefd;
if ((resdirfd = open(settings->results_path, O_DIRECTORY | O_RDONLY)) < 0) {
/* Initialize state should have done this */
@@ -991,13 +1003,23 @@ bool execute(struct execute_state *state,
/* TODO: On resume, don't rewrite, verify that content matches current instead */
if ((unamefd = openat(resdirfd, "uname.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0) {
- fprintf(stderr, "Error: Failure creating opening uname.txt: %s\n",
+ fprintf(stderr, "Error: Failure opening uname.txt: %s\n",
strerror(errno));
close(testdirfd);
close(resdirfd);
return false;
}
+ if ((timefd = openat(resdirfd, "starttime.txt", O_CREAT | O_WRONLY | O_EXCL, 0666)) >= 0) {
+ /*
+ * Ignore failure to open. If this is a resume, we
+ * don't want to overwrite. For other errors, we
+ * ignore the start time.
+ */
+ dprintf(timefd, "%f\n", timeofday_double());
+ close(timefd);
+ }
+
init_watchdogs(settings);
if (!uname(&unamebuf)) {
@@ -1031,6 +1053,11 @@ bool execute(struct execute_state *state,
}
}
+ if ((timefd = openat(resdirfd, "endtime.txt", O_CREAT | O_WRONLY | O_EXCL, 0666)) >= 0) {
+ dprintf(timefd, "%f\n", timeofday_double());
+ close(timefd);
+ }
+
close(testdirfd);
close(resdirfd);
close_watchdogs(settings);
diff --git a/runner/resultgen.c b/runner/resultgen.c
index e8a60083..11eff9d3 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -987,9 +987,9 @@ bool generate_results(int dirfd)
{
struct settings settings;
struct job_list job_list;
- struct json_object *obj;
+ struct json_object *obj, *elapsed;
struct results results;
- int resultsfd, testdirfd, unamefd;
+ int resultsfd, testdirfd, fd;
const char *json_string;
size_t i;
@@ -1020,17 +1020,33 @@ bool generate_results(int dirfd)
json_object_new_string(settings.name) :
json_object_new_string(""));
- if ((unamefd = openat(dirfd, "uname.txt", O_RDONLY)) >= 0) {
+ if ((fd = openat(dirfd, "uname.txt", O_RDONLY)) >= 0) {
char buf[128];
- ssize_t r = read(unamefd, buf, 128);
+ ssize_t r = read(fd, buf, sizeof(buf));
if (r > 0 && buf[r - 1] == '\n')
r--;
json_object_object_add(obj, "uname",
json_object_new_string_len(buf, r));
- close(unamefd);
+ close(fd);
+ }
+
+ elapsed = json_object_new_object();
+ json_object_object_add(elapsed, "__type__", json_object_new_string("TimeAttribute"));
+ if ((fd = openat(dirfd, "starttime.txt", O_RDONLY)) >= 0) {
+ char buf[128] = {};
+ read(fd, buf, sizeof(buf));
+ json_object_object_add(elapsed, "start", json_object_new_double(atof(buf)));
+ close(fd);
+ }
+ if ((fd = openat(dirfd, "endtime.txt", O_RDONLY)) >= 0) {
+ char buf[128] = {};
+ read(fd, buf, sizeof(buf));
+ json_object_object_add(elapsed, "end", json_object_new_double(atof(buf)));
+ close(fd);
}
+ json_object_object_add(obj, "time_elapsed", elapsed);
create_result_root_nodes(obj, &results);
@@ -1045,7 +1061,6 @@ bool generate_results(int dirfd)
*
* - lspci
* - options
- * - time_elapsed
*/
for (i = 0; i < job_list.size; i++) {
--
2.18.0
More information about the igt-dev
mailing list