This is an automated email from Gerrit.

Hsiangkai Wang ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/1570

-- gerrit

commit 7b7a3838c62d849199a6f6af028bb1ee4e93135d
Author: Hsiangkai Wang <[email protected]>
Date:   Mon Jun 10 11:38:03 2013 +0800

    target: Make profiling function more readable
    
    Change variable name 'length' to 'numBuckets'.  It is more readable.
    
    Change-Id: If9550e3a005bae98cda078be77a10b127bc6ecf5
    Signed-off-by: Hsiangkai Wang <[email protected]>

diff --git a/src/target/target.c b/src/target/target.c
index e4235ed..b3bb95c 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3437,25 +3437,26 @@ static void writeGmon(uint32_t *samples, uint32_t 
sampleNum, const char *filenam
                if (max < samples[i])
                        max = samples[i];
        }
+       max++;
 
-       int addressSpace = (max - min + 1);
+       int addressSpace = max - min;
        assert(addressSpace >= 2);
 
-       static const uint32_t maxBuckets = 16 * 1024; /* maximum buckets. */
-       uint32_t length = addressSpace;
-       if (length > maxBuckets)
-               length = maxBuckets;
-       int *buckets = malloc(sizeof(int)*length);
+       static const uint32_t maxBuckets = 128 * 1024;
+       uint32_t numBuckets = addressSpace;
+       if (numBuckets > maxBuckets)
+               numBuckets = maxBuckets;
+       int *buckets = malloc(sizeof(int) * numBuckets);
        if (buckets == NULL) {
                fclose(f);
                return;
        }
-       memset(buckets, 0, sizeof(int) * length);
+       memset(buckets, 0, sizeof(int) * numBuckets);
        for (i = 0; i < sampleNum; i++) {
                uint32_t address = samples[i];
                long long a = address - min;
-               long long b = length - 1;
-               long long c = addressSpace - 1;
+               long long b = numBuckets;
+               long long c = addressSpace;
                int index_t = (a * b) / c; /* danger!!!! int32 overflows */
                buckets[index_t]++;
        }
@@ -3463,7 +3464,7 @@ static void writeGmon(uint32_t *samples, uint32_t 
sampleNum, const char *filenam
        /* append binary memory gmon.out &profile_hist_hdr 
((char*)&profile_hist_hdr + sizeof(struct gmon_hist_hdr)) */
        writeLong(f, min);                      /* low_pc */
        writeLong(f, max);                      /* high_pc */
-       writeLong(f, length);           /* # of samples */
+       writeLong(f, numBuckets);       /* # of buckets */
        writeLong(f, 100);                      /* KLUDGE! We lie, ca. 100Hz 
best case. */
        writeString(f, "seconds");
        for (i = 0; i < (15-strlen("seconds")); i++)
@@ -3472,9 +3473,9 @@ static void writeGmon(uint32_t *samples, uint32_t 
sampleNum, const char *filenam
 
        /*append binary memory gmon.out profile_hist_data (profile_hist_data + 
profile_hist_hdr.hist_size) */
 
-       char *data = malloc(2 * length);
+       char *data = malloc(2 * numBuckets);
        if (data != NULL) {
-               for (i = 0; i < length; i++) {
+               for (i = 0; i < numBuckets; i++) {
                        int val;
                        val = buckets[i];
                        if (val > 65535)
@@ -3483,7 +3484,7 @@ static void writeGmon(uint32_t *samples, uint32_t 
sampleNum, const char *filenam
                        data[i * 2 + 1] = (val >> 8) & 0xff;
                }
                free(buckets);
-               writeData(f, data, length * 2);
+               writeData(f, data, numBuckets * 2);
                free(data);
        } else
                free(buckets);

-- 

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to