Exemplo n.º 1
0
void fps_init(Fps* s)
{
    s->lastTime = _now_ms();
    s->firstTime = 0.;
    s->firstFrame = 0;
    s->numFrames  = 0;
}
Exemplo n.º 2
0
void fps_endFrame(Fps* s)
{
    double now = _now_ms();
    double renderTime = now - s->frameTime;
    double frameTime  = now - s->lastTime;
    int nn;

    if (now - s->firstTime >= MAX_PERIOD_MS) {
        if (s->numFrames > 0) {
            double minRender, maxRender, avgRender;
            double minFrame, maxFrame, avgFrame;
            int count;

            nn = s->firstFrame;
            minRender = maxRender = avgRender = s->frames[nn].renderTime;
            minFrame  = maxFrame  = avgFrame  = s->frames[nn].frameTime;
            for (count = s->numFrames; count > 0; count-- ) {
                nn += 1;
                if (nn >= MAX_FRAME_STATS)
                    nn -= MAX_FRAME_STATS;
                double render = s->frames[nn].renderTime;
                if (render < minRender) minRender = render;
                if (render > maxRender) maxRender = render;
                double frame = s->frames[nn].frameTime;
                if (frame < minFrame) minFrame = frame;
                if (frame > maxFrame) maxFrame = frame;
                avgRender += render;
                avgFrame  += frame;
            }
            avgRender /= s->numFrames;
            avgFrame  /= s->numFrames;

            LOGI("frame/s (avg,min,max) = (%.1f,%.1f,%.1f) "
                 "render time ms (avg,min,max) = (%.1f,%.1f,%.1f)\n",
                 1000./avgFrame, 1000./maxFrame, 1000./minFrame,
                 avgRender, minRender, maxRender);
        }
        s->numFrames  = 0;
        s->firstFrame = 0;
        s->firstTime  = now;
    }

    nn = s->firstFrame + s->numFrames;
    if (nn >= MAX_FRAME_STATS)
        nn -= MAX_FRAME_STATS;

    s->frames[nn].renderTime = renderTime;
    s->frames[nn].frameTime  = frameTime;

    if (s->numFrames < MAX_FRAME_STATS) {
        s->numFrames += 1;
    } else {
        s->firstFrame += 1;
        if (s->firstFrame >= MAX_FRAME_STATS)
            s->firstFrame -= MAX_FRAME_STATS;
    }

    s->lastTime = now;
}
Exemplo n.º 3
0
EXPORT_SYM bool
hdfs_future_get_timeout(struct hdfs_rpc_response_future *future, struct hdfs_object **object, uint64_t ms)
{
	uint64_t absms;

	absms = _now_ms() + ms;
	_lock(&future->fu_lock);
	while (!future->fu_res && _now_ms() < absms)
		_waitlimit(&future->fu_lock, &future->fu_cond, absms);
	if (!future->fu_res) {
		_unlock(&future->fu_lock);
		return false;
	}
	_unlock(&future->fu_lock);
	*object = future->fu_res;

	_namenode_decref(future->fu_namenode);
	memset(future, 0, sizeof *future);
	return true;
}
Exemplo n.º 4
0
EXPORT_SYM bool
hdfs_future_get_timeout(struct hdfs_rpc_response_future *future, struct hdfs_object **object, uint64_t ms)
{
	uint64_t absms;

	ASSERT(future->fu_inited && future->fu_invoked);

	absms = _now_ms() + ms;
	_lock(&future->fu_lock);
	while (!future->fu_res && _now_ms() < absms)
		_waitlimit(&future->fu_lock, &future->fu_cond, absms);
	if (!future->fu_res) {
		_unlock(&future->fu_lock);
		return false;
	}
	_unlock(&future->fu_lock);
	*object = future->fu_res;

	hdfs_rpc_response_future_clean(future);
	return true;
}
Exemplo n.º 5
0
void fps_startFrame(Fps* s)
{
    s->frameTime = _now_ms();
}