This is an automated email from Gerrit.

"Richard Allen <rsa...@gmail.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/8604

-- gerrit

commit 50097fd6f6d0a645597611354ff958de798ed1df
Author: Richard Allen <rsa...@gmail.com>
Date:   Fri Nov 29 12:27:45 2024 -0600

    target: sort pc samples before storing
    
    Add a comparator and pre-sort the program-counter
    samples before saving histogram. This makes future
    improvements much easier to implement.
    
    Change-Id: I38276dd1be011ce5781b0264b7cda08c32a1a2a2
    Signed-off-by: Richard Allen <rsa...@gmail.com>

diff --git a/src/target/target.c b/src/target/target.c
index d563be6d5f..894e8e8f85 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -30,6 +30,7 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
 #include <helper/align.h>
 #include <helper/nvp.h>
 #include <helper/time_support.h>
@@ -4310,6 +4311,18 @@ static void write_gmon(const uint32_t *samples, uint32_t 
sample_num, const char
        fclose(f);
 }
 
+static int compare_pc(const void *p1, const void *p2)
+{
+       uint32_t lhs, rhs;
+       memcpy(&lhs, p1, sizeof(lhs));
+       memcpy(&rhs, p2, sizeof(rhs));
+       if (lhs < rhs)
+               return -1;
+       else if (lhs > rhs)
+               return 1;
+       return 0;
+}
+
 /* profiling samples the CPU PC as quickly as OpenOCD is able,
  * which will be used as a random sampling of PC */
 COMMAND_HANDLER(handle_profile_command)
@@ -4392,6 +4405,8 @@ COMMAND_HANDLER(handle_profile_command)
                return retval;
        }
 
+       qsort(samples, num_of_samples, sizeof(samples[0]), compare_pc);
+
        write_gmon(samples, num_of_samples, CMD_ARGV[1],
                   with_range, start_address, end_address, target, duration_ms);
        command_print(CMD, "Wrote %s", CMD_ARGV[1]);

-- 

Reply via email to