dm_perf.c

来自「优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐」· C语言 代码 · 共 64 行

C
64
字号
/*----------------------------------------------------------------------
 * Copyright (C) 2000 Intel Corp.
 *
 * This file contains the performance counter functions.
 */
#include <string.h>
#include <stdio.h>
#include "systypes.h"
#include "dm_perf.h"

/*----------------------------------------------------------------------
 *
 */
void DM_PerfCount (DM_Perf_T *p, unsigned delta)
{
    p->count++;
    p->total += delta;
    if (delta < p->min)
    {
        p->min = delta;
        p->minCount = p->count;
    }
    if (delta > p->max)
    {
        p->max = delta;
        p->maxCount = p->count;
    }
}

/*----------------------------------------------------------------------
 *
 */
void DM_PerfInit (DM_Perf_T *p)
{
    p->count = 0;
    p->total = 0;
    p->min = 0xffffffff;
    p->max = 0;
}

/*----------------------------------------------------------------------
 *
 */
void DM_PerfDisplay (DM_Perf_T *p, char *tag, unsigned timebase)
{
    printf ("%s total %d (min@%d,max@%d)", tag,
        p->count, p->minCount, p->maxCount);

    if (p->count && timebase)
    {
        unsigned ticks = p->total / p->count;
        printf ("%s avg %d ticks, %3.2fus", tag,
            ticks,
            ((float) ticks / timebase) * 1000000);
        printf ("%s min %d ticks, %3.2fus", tag,
            p->min,
            ((float) p->min / timebase) * 1000000);
        printf ("%s max %d ticks, %3.2fus", tag,
            p->max,
            ((float) p->max / timebase) * 1000000);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?