static void internal_add_call_latency()

in win32/src/gballoc_hl_metrics.c [279:348]


static void internal_add_call_latency(LATENCY_BUCKET* latency_buckets, size_t size, int32_t latency)
{
    size_t bucket = determine_latency_bucket_for_size(size);

    /* Codes_SRS_GBALLOC_HL_METRICS_01_043: [ gballoc_hl_malloc shall add the computed latency to the running malloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_046: [ gballoc_hl_malloc_2 shall add the computed latency to the running malloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_050: [ gballoc_hl_malloc_flex shall add the computed latency to the running malloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_054: [ gballoc_hl_calloc shall add the computed latency to the running calloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_058: [ gballoc_hl_realloc shall add the computed latency to the running realloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_062: [ gballoc_hl_realloc_2 shall add the computed latency to the running realloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_066: [ gballoc_hl_realloc_flex shall add the computed latency to the running realloc latency sum used to compute the average. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_070: [ gballoc_hl_free shall add the computed latency to the running free latency sum used to compute the average. ]*/
    (void)interlocked_add_64(&latency_buckets[bucket].latency_sum, latency);
    do
    {
        /* Codes_SRS_GBALLOC_HL_METRICS_01_044: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc shall store it as the new minimum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_047: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc_2 shall store it as the new minimum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_051: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_malloc_flex shall store it as the new minimum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_055: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_calloc shall store it as the new minimum calloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_059: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc shall store it as the new minimum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_063: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc_2 shall store it as the new minimum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_067: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_realloc_flex shall store it as the new minimum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_071: [ If the computed latency is less than the minimum tracked latency, gballoc_hl_free shall store it as the new minimum free latency. ]*/
        int32_t current_min = interlocked_add(&latency_buckets[bucket].latency_min, 0);
        if (current_min > latency)
        {
            if (interlocked_compare_exchange(&latency_buckets[bucket].latency_min, latency, current_min) == current_min)
            {
                break;
            }
        }
        else
        {
            break;
        }
    } while (1);
    do
    {
        /* Codes_SRS_GBALLOC_HL_METRICS_01_045: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc shall store it as the new maximum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_048: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc_2 shall store it as the new maximum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_052: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_malloc_flex shall store it as the new maximum malloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_056: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_calloc shall store it as the new maximum calloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_060: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc shall store it as the new maximum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_064: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc_2 shall store it as the new maximum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_068: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_realloc_flex shall store it as the new maximum realloc latency. ]*/
        /* Codes_SRS_GBALLOC_HL_METRICS_01_072: [ If the computed latency is more than the maximum tracked latency, gballoc_hl_free shall store it as the new maximum free latency. ]*/
        int32_t current_max = interlocked_add(&latency_buckets[bucket].latency_max, 0);
        if (current_max < latency)
        {
            if (interlocked_compare_exchange(&latency_buckets[bucket].latency_max, latency, current_max) == current_max)
            {
                break;
            }
        }
        else
        {
            break;
        }
    } while (1);
    
    /* Codes_SRS_GBALLOC_HL_METRICS_01_042: [ gballoc_hl_malloc shall increment the count of malloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_049: [ gballoc_hl_malloc_2 shall increment the count of malloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_053: [ gballoc_hl_malloc_flex shall increment the count of malloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_057: [ gballoc_hl_calloc shall increment the count of calloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_061: [ gballoc_hl_realloc shall increment the count of realloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_065: [ gballoc_hl_realloc_2 shall increment the count of realloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_069: [ gballoc_hl_realloc_flex shall increment the count of realloc latency samples. ]*/
    /* Codes_SRS_GBALLOC_HL_METRICS_01_073: [ gballoc_hl_free shall increment the count of free latency samples. ]*/
    (void)interlocked_increment(&latency_buckets[bucket].count);
}