profiling: write "correct" sample rate to gmon output 21/4221/4
authorKarl Palsson <karlp@tweak.net.au>
Fri, 8 Sep 2017 15:44:52 +0000 (15:44 +0000)
committerPaul Fertser <fercerpav@gmail.com>
Sat, 13 Jan 2018 09:32:43 +0000 (09:32 +0000)
This duration vs sample count is _significantly_ closer to the truth
than simply declaring the value to be 100Hz.

Change-Id: Ie8d8bdf1959e1aa7cead0631cd2c86afe77d1efc
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-on: http://openocd.zylin.com/4221
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
src/target/target.c

index a9907b0c3ef92f042dd11d5495084a7fe6419a47..d6781a3c4e087f16ad825709820ef04d7b220f4e 100644 (file)
@@ -3838,7 +3838,7 @@ typedef unsigned char UNIT[2];  /* unit of profiling */
 
 /* Dump a gmon.out histogram file. */
 static void write_gmon(uint32_t *samples, uint32_t sampleNum, const char *filename, bool with_range,
-                       uint32_t start_address, uint32_t end_address, struct target *target)
+                       uint32_t start_address, uint32_t end_address, struct target *target, uint32_t duration_ms)
 {
        uint32_t i;
        FILE *f = fopen(filename, "w");
@@ -3906,7 +3906,8 @@ static void write_gmon(uint32_t *samples, uint32_t sampleNum, const char *filena
        writeLong(f, min, target);                      /* low_pc */
        writeLong(f, max, target);                      /* high_pc */
        writeLong(f, numBuckets, target);       /* # of buckets */
-       writeLong(f, 100, target);                      /* KLUDGE! We lie, ca. 100Hz best case. */
+       float sample_rate = sampleNum / (duration_ms / 1000.0);
+       writeLong(f, sample_rate, target);
        writeString(f, "seconds");
        for (i = 0; i < (15-strlen("seconds")); i++)
                writeData(f, &zero, 1);
@@ -3955,6 +3956,7 @@ COMMAND_HANDLER(handle_profile_command)
                return ERROR_FAIL;
        }
 
+       uint64_t timestart_ms = timeval_ms();
        /**
         * Some cores let us sample the PC without the
         * annoying halt/resume step; for example, ARMv7 PCSR.
@@ -3966,6 +3968,7 @@ COMMAND_HANDLER(handle_profile_command)
                free(samples);
                return retval;
        }
+       uint32_t duration_ms = timeval_ms() - timestart_ms;
 
        assert(num_of_samples <= MAX_PROFILE_SAMPLE_NUM);
 
@@ -3998,7 +4001,7 @@ COMMAND_HANDLER(handle_profile_command)
        }
 
        write_gmon(samples, num_of_samples, CMD_ARGV[1],
-                  with_range, start_address, end_address, target);
+                  with_range, start_address, end_address, target, duration_ms);
        command_print(CMD_CTX, "Wrote %s", CMD_ARGV[1]);
 
        free(samples);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)