perf header: Use last modification time for timestamp
authorMichael Petlan <mpetlan@redhat.com>
Tue, 14 Jan 2020 10:42:36 +0000 (11:42 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 15 Jan 2020 13:17:20 +0000 (10:17 -0300)
Using .st_ctime clobbers the timestamp information in perf report header
whenever any operation is done with the file. Even tar-ing and untar-ing
the perf.data file (which preserves the file last modification timestamp)
doesn't prevent that:

    [Michael@Diego tmp]$ ls -l perf.data
-> -rw-------. 1 Michael Michael 169888 Dec  2 15:23 perf.data

[Michael@Diego tmp]$ perf report --header-only
# ========
-> # captured on    : Mon Dec  2 15:23:42 2019
 [...]

[Michael@Diego tmp]$ tar c perf.data | xz > perf.data.tar.xz
[Michael@Diego tmp]$ mkdir aaa
[Michael@Diego tmp]$ cd aaa
[Michael@Diego aaa]$ xzcat ../perf.data.tar.xz | tar x
[Michael@Diego aaa]$ ls -l -a
total 172
drwxrwxr-x. 2 Michael Michael     23 Jan 14 11:26 .
drwxrwxr-x. 6 Michael Michael   4096 Jan 14 11:26 ..
-> -rw-------. 1 Michael Michael 169888 Dec  2 15:23 perf.data

[Michael@Diego aaa]$ perf report --header-only
# ========
-> # captured on    : Tue Jan 14 11:26:16 2020
 [...]

When using .st_mtime instead, correct information is printed:

[Michael@Diego aaa]$ ~/acme/tools/perf/perf report --header-only
# ========
-> # captured on    : Mon Dec  2 15:23:42 2019
 [...]

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
LPU-Reference: 20200114104236.31555-1-mpetlan@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/header.c

index 93ad278..4246e74 100644 (file)
@@ -2922,7 +2922,7 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
        if (ret == -1)
                return -1;
 
-       stctime = st.st_ctime;
+       stctime = st.st_mtime;
        fprintf(fp, "# captured on    : %s", ctime(&stctime));
 
        fprintf(fp, "# header version : %u\n", header->version);