Commit 86a235d4 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Improved timing metrics.

Added header and source files to simplify timing.  You now just call
functions to mark the beginning and end of function calls.
parent 32510c13
......@@ -11,6 +11,7 @@
#include <IceTDevDiagnostics.h>
#include <IceTDevState.h>
#include <IceTDevTiming.h>
#include <IceTDevGLImage.h>
......@@ -139,7 +140,8 @@ static void finalizeOpenGLRender(const IceTImage image,
IceTDrawCallbackType original_callback)
{
IceTInt display_tile;
IceTDouble buf_write_time;
icetTimingBufferWriteBegin();
/* Restore core IceT callback. */
icetDrawCallback(original_callback);
......@@ -150,7 +152,6 @@ static void finalizeOpenGLRender(const IceTImage image,
/* Paste final image back to buffer if enabled. */
icetGetIntegerv(ICET_TILE_DISPLAYED, &display_tile);
buf_write_time = icetWallTime();
if (display_tile >= 0) {
IceTEnum color_format = icetImageGetColorFormat(image);
......@@ -168,8 +169,7 @@ static void finalizeOpenGLRender(const IceTImage image,
glLoadMatrixd(modelview_matrix);
/* Calculate display times. */
buf_write_time = icetWallTime() - buf_write_time;
icetStateSetDouble(ICET_BUFFER_WRITE_TIME, buf_write_time);
icetTimingBufferWriteEnd();
}
static void correctOpenGLRenderTimes(IceTDouble total_time)
......
......@@ -13,6 +13,7 @@
#include <IceTDevDiagnostics.h>
#include <IceTDevState.h>
#include <IceTDevTiming.h>
void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
const IceTDouble *modelview_matrix,
......@@ -56,6 +57,11 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
(*callback)();
}
/* Temporarily stop render time while reading back buffer. */
icetTimingRenderEnd();
icetTimingBufferReadBegin();
/* Read the OpenGL buffers. */
{
IceTEnum color_format = icetImageGetColorFormat(result);
......@@ -63,9 +69,6 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
IceTEnum readbuffer;
IceTSizeType x_offset = gl_viewport[0] + readback_viewport[0];
IceTSizeType y_offset = gl_viewport[1] + readback_viewport[1];
IceTDouble read_time;
IceTDouble render_time;
IceTDouble timer;
glPixelStorei(GL_PACK_ROW_LENGTH, (GLint)icetImageGetWidth(result));
......@@ -78,8 +81,6 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
icetGetEnumv(ICET_GL_READ_BUFFER, &readbuffer);
glReadBuffer(readbuffer);
timer = icetWallTime();
if (color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
IceTUInt *colorBuffer = icetImageGetColorui(result);
glReadPixels((GLint)x_offset,
......@@ -121,15 +122,11 @@ void icetGLDrawCallbackFunction(const IceTDouble *projection_matrix,
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
/* glPixelStorei(GL_PACK_SKIP_PIXELS, 0); */
/* glPixelStorei(GL_PACK_SKIP_ROWS, 0); */
}
icetGetDoublev(ICET_BUFFER_READ_TIME, &read_time);
read_time += icetWallTime() - timer;
icetStateSetDouble(ICET_BUFFER_READ_TIME, read_time);
icetTimingBufferReadEnd();
/* Subtract read time from render time since the render time is being
recorded as we are in this funtion. */
icetGetDoublev(ICET_RENDER_TIME, &render_time);
render_time -= read_time;
icetStateSetDouble(ICET_RENDER_TIME, render_time);
}
/* Start render timer again. It's going to be shut off immediately on
return anyway, but the calling function expects it to be running. */
icetTimingRenderBegin();
}
......@@ -12,6 +12,7 @@ SET(ICET_SRCS
diagnostics.c
communication.c
tiles.c
timing.c
matrix.c
projections.c
draw.c
......
......@@ -74,12 +74,9 @@
#ifdef DEBUG
IceTSizeType _totalcount = 0;
#endif
IceTDouble _timer;
IceTDouble _compress_time;
IceTSizeType _compressed_size;
icetGetDoublev(ICET_COMPRESS_TIME, &_compress_time);
_timer = icetWallTime();
icetTimingCompressBegin();
_dest = ICET_IMAGE_DATA(CT_COMPRESSED_IMAGE);
......@@ -220,8 +217,7 @@
}
#endif /*DEBUG*/
_compress_time += icetWallTime() - _timer;
icetStateSetDouble(ICET_COMPRESS_TIME, _compress_time);
icetTimingCompressEnd();
_compressed_size
= (IceTSizeType)
......
......@@ -61,12 +61,9 @@
IceTEnum _color_format, _depth_format;
IceTSizeType _pixel_count;
IceTEnum _composite_mode;
#ifdef TIME_DECOMPRESSION
IceTDouble _timer;
IceTDouble _compress_time;
icetGetDoublev(ICET_COMPRESS_TIME, &_compress_time);
_timer = icetWallTime();
#ifdef TIME_DECOMPRESSION
icetTimingCompressBegin();
#endif /* TIME_DECOMPRESSION */
icetGetEnumv(ICET_COMPOSITE_MODE, &_composite_mode);
......@@ -330,8 +327,7 @@
}
#ifdef TIME_DECOMPRESSION
_compress_time += icetWallTime() - _timer;
icetStateSetDouble(ICET_COMPRESS_TIME, _compress_time);
icetTimingCompressEnd();
#endif
}
......
......@@ -15,6 +15,7 @@
#include <IceTDevMatrix.h>
#include <IceTDevState.h>
#include <IceTDevStrategySelect.h>
#include <IceTDevTiming.h>
#include <stdlib.h>
#include <string.h>
......@@ -714,12 +715,10 @@ static void drawCorrectBackground(IceTImage image,
const IceTFloat *background_color,
IceTUInt background_color_word)
{
IceTSizeType pixels =icetImageGetWidth(image)*icetImageGetHeight(image);
IceTSizeType pixels = icetImageGetWidth(image)*icetImageGetHeight(image);
IceTEnum color_format = icetImageGetColorFormat(image);
IceTDouble blend_time;
icetGetDoublev(ICET_BLEND_TIME, &blend_time);
blend_time = icetWallTime() - blend_time;
icetTimingBlendBegin();
if (color_format == ICET_IMAGE_COLOR_RGBA_UBYTE) {
IceTUByte *color = icetImageGetColorub(image);
......@@ -739,8 +738,7 @@ static void drawCorrectBackground(IceTImage image,
" with color blending.", ICET_SANITY_CHECK_FAIL);
}
blend_time = icetWallTime() - blend_time;
icetStateSetDouble(ICET_BLEND_TIME, blend_time);
icetTimingBlendEnd();
}
IceTImage icetDrawFrame(const IceTDouble *projection_matrix,
......@@ -769,7 +767,7 @@ IceTImage icetDrawFrame(const IceTDouble *projection_matrix,
}
icetStateResetTiming();
total_time = icetWallTime();
icetTimingDrawFrameBegin();
icetStateSetDoublev(ICET_PROJECTION_MATRIX, 16, projection_matrix);
icetStateSetDoublev(ICET_MODELVIEW_MATRIX, 16, modelview_matrix);
......@@ -811,8 +809,9 @@ IceTImage icetDrawFrame(const IceTDouble *projection_matrix,
icetGetDoublev(ICET_RENDER_TIME, &render_time);
icetGetDoublev(ICET_BUFFER_READ_TIME, &buf_read_time);
total_time = icetWallTime() - total_time;
icetStateSetDouble(ICET_TOTAL_DRAW_TIME, total_time);
icetTimingDrawFrameEnd();
icetGetDoublev(ICET_TOTAL_DRAW_TIME, &total_time);
compose_time = total_time - render_time - buf_read_time;
icetStateSetDouble(ICET_COMPOSITE_TIME, compose_time);
......
......@@ -15,6 +15,7 @@
#include <IceTDevState.h>
#include <IceTDevDiagnostics.h>
#include <IceTDevMatrix.h>
#include <IceTDevTiming.h>
#include <stdlib.h>
#include <string.h>
......@@ -1592,8 +1593,6 @@ void icetGetTileImage(IceTInt tile, IceTImage image)
const IceTInt *viewports;
IceTSizeType width, height;
IceTImage rendered_image;
IceTDouble read_time;
IceTDouble timer;
viewports = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS);
width = viewports[4*tile+2];
......@@ -1602,7 +1601,7 @@ void icetGetTileImage(IceTInt tile, IceTImage image)
rendered_image = renderTile(tile, screen_viewport, target_viewport, image);
timer = icetWallTime();
icetTimingBufferReadBegin();
if (icetImageEqual(rendered_image, image)) {
/* Check to make sure the screen and target viewports are also equal. */
......@@ -1621,9 +1620,7 @@ void icetGetTileImage(IceTInt tile, IceTImage image)
icetImageClearAroundRegion(image, target_viewport);
icetGetDoublev(ICET_BUFFER_READ_TIME, &read_time);
read_time += icetWallTime() - timer;
icetStateSetDouble(ICET_BUFFER_READ_TIME, read_time);
icetTimingBufferReadEnd();
}
void icetGetCompressedTileImage(IceTInt tile, IceTSparseImage compressed_image)
......@@ -1735,8 +1732,6 @@ void icetComposite(IceTImage destBuffer, const IceTImage srcBuffer,
IceTSizeType i;
IceTEnum composite_mode;
IceTEnum color_format, depth_format;
IceTDouble timer;
IceTDouble compare_time;
pixels = icetImageGetNumPixels(destBuffer);
if (pixels != icetImageGetNumPixels(srcBuffer)) {
......@@ -1757,8 +1752,7 @@ void icetComposite(IceTImage destBuffer, const IceTImage srcBuffer,
icetGetEnumv(ICET_COMPOSITE_MODE, &composite_mode);
icetGetDoublev(ICET_COMPARE_TIME, &compare_time);
timer = icetWallTime();
icetTimingBlendBegin();
if (composite_mode == ICET_COMPOSITE_MODE_Z_BUFFER) {
if (depth_format == ICET_IMAGE_DEPTH_FLOAT) {
......@@ -1849,8 +1843,7 @@ void icetComposite(IceTImage destBuffer, const IceTImage srcBuffer,
ICET_SANITY_CHECK_FAIL);
}
compare_time += icetWallTime() - timer;
icetStateSetDouble(ICET_COMPARE_TIME, compare_time);
icetTimingBlendEnd();
}
void icetCompressedComposite(IceTImage destBuffer,
......@@ -1869,11 +1862,7 @@ void icetCompressedSubComposite(IceTImage destBuffer,
const IceTSparseImage srcBuffer,
int srcOnTop)
{
IceTDouble timer;
IceTDouble compare_time;
icetGetDoublev(ICET_COMPARE_TIME, &compare_time);
timer = icetWallTime();
icetTimingBlendBegin();
if (srcOnTop) {
#define INPUT_SPARSE_IMAGE srcBuffer
......@@ -1895,8 +1884,7 @@ void icetCompressedSubComposite(IceTImage destBuffer,
#include "decompress_func_body.h"
}
compare_time += icetWallTime() - timer;
icetStateSetDouble(ICET_COMPARE_TIME, compare_time);
icetTimingBlendEnd();
}
void icetCompressedCompressedComposite(const IceTSparseImage front_buffer,
......@@ -1930,7 +1918,6 @@ static IceTImage renderTile(int tile,
IceTBoolean use_floating_viewport;
IceTDrawCallbackType drawfunc;
IceTVoid *value;
IceTDouble render_time;
IceTDouble timer;
IceTInt readback_viewport[4];
IceTImage render_buffer;
......@@ -1938,6 +1925,8 @@ static IceTImage renderTile(int tile,
IceTDouble modelview_matrix[16];
IceTFloat background_color[4];
icetTimingRenderBegin();
icetRaiseDebug1("Rendering tile %d", tile);
contained_viewport = icetUnsafeStateGetInteger(ICET_CONTAINED_VIEWPORT);
tile_viewport = icetUnsafeStateGetInteger(ICET_TILE_VIEWPORTS) + 4*tile;
......@@ -2140,9 +2129,8 @@ static IceTImage renderTile(int tile,
timer = icetWallTime();
(*drawfunc)(projection_matrix, modelview_matrix, background_color,
readback_viewport, render_buffer);
icetGetDoublev(ICET_RENDER_TIME, &render_time);
render_time += icetWallTime() - timer;
icetStateSetDouble(ICET_RENDER_TIME, render_time);
icetTimingRenderEnd();
return render_buffer;
}
......
......@@ -15,6 +15,7 @@
#include <IceTDevDiagnostics.h>
#include <IceTDevPorting.h>
#include <IceTDevStrategySelect.h>
#include <IceTDevTiming.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -655,19 +656,6 @@ IceTTimeStamp icetGetTimeStamp(void)
return current_time++;
}
void icetStateResetTiming(void)
{
icetStateSetDouble(ICET_RENDER_TIME, 0.0);
icetStateSetDouble(ICET_BUFFER_READ_TIME, 0.0);
icetStateSetDouble(ICET_BUFFER_WRITE_TIME, 0.0);
icetStateSetDouble(ICET_COMPRESS_TIME, 0.0);
icetStateSetDouble(ICET_COMPARE_TIME, 0.0);
icetStateSetDouble(ICET_COMPOSITE_TIME, 0.0);
icetStateSetDouble(ICET_TOTAL_DRAW_TIME, 0.0);
icetStateSetInteger(ICET_BYTES_SENT, 0);
}
void icetStateDump(void)
{
IceTEnum pname;
......
/* -*- c -*- *******************************************************/
/*
* Copyright (C) 2011 Sandia Corporation
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* This source code is released under the New BSD License.
*/
#include <IceTDevTiming.h>
#include <IceTDevDiagnostics.h>
#include <IceTDevState.h>
#include <stdlib.h>
#include <stdio.h>
void icetStateResetTiming(void)
{
icetStateSetDouble(ICET_RENDER_TIME, 0.0);
icetStateSetDouble(ICET_BUFFER_READ_TIME, 0.0);
icetStateSetDouble(ICET_BUFFER_WRITE_TIME, 0.0);
icetStateSetDouble(ICET_COMPRESS_TIME, 0.0);
icetStateSetDouble(ICET_BLEND_TIME, 0.0);
icetStateSetDouble(ICET_COMPOSITE_TIME, 0.0);
icetStateSetDouble(ICET_TOTAL_DRAW_TIME, 0.0);
icetStateSetInteger(ICET_DRAW_TIME_ID, 0);
icetStateSetInteger(ICET_SUBFUNC_TIME_ID, 0);
icetStateSetInteger(ICET_BYTES_SENT, 0);
}
static void icetTimingBegin(IceTEnum start_pname,
IceTEnum id_pname,
IceTEnum result_pname,
const char *name)
{
icetRaiseDebug1("Beginning %s", name);
{
IceTInt current_id;
icetGetIntegerv(id_pname, &current_id);
if (current_id != 0) {
char message[256];
sprintf(message,
"Called start for timer 0x%x,"
" but end never called for timer 0x%x",
result_pname,
current_id);
icetRaiseError(message, ICET_SANITY_CHECK_FAIL);
}
}
icetStateSetInteger(id_pname, result_pname);
icetStateSetDouble(start_pname, icetWallTime());
}
static void icetTimingEnd(IceTEnum start_pname,
IceTEnum id_pname,
IceTEnum result_pname,
const char *name)
{
icetRaiseDebug1("Ending %s", name);
{
IceTInt current_id;
icetGetIntegerv(id_pname, &current_id);
if ((IceTEnum)current_id != result_pname) {
char message[256];
sprintf(message,
"Started timer 0x%x, but ended timer 0x%x",
result_pname,
current_id);
icetRaiseError(message, ICET_SANITY_CHECK_FAIL);
}
}
icetStateSetInteger(id_pname, 0);
{
IceTDouble start_time;
IceTDouble old_time;
icetGetDoublev(start_pname, &start_time);
icetGetDoublev(result_pname, &old_time);
icetStateSetDouble(result_pname, icetWallTime() - start_time);
}
}
void icetTimingRenderBegin(void)
{
icetTimingBegin(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_RENDER_TIME,
"render");
}
void icetTimingRenderEnd(void)
{
icetTimingEnd(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_RENDER_TIME,
"render");
}
void icetTimingBufferReadBegin(void)
{
icetTimingBegin(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BUFFER_READ_TIME,
"buffer read");
}
void icetTimingBufferReadEnd(void)
{
icetTimingEnd(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BUFFER_READ_TIME,
"buffer read");
}
void icetTimingBufferWriteBegin(void)
{
icetTimingBegin(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BUFFER_WRITE_TIME,
"buffer write");
}
void icetTimingBufferWriteEnd(void)
{
icetTimingEnd(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BUFFER_WRITE_TIME,
"buffer write");
}
void icetTimingCompressBegin(void)
{
icetTimingBegin(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_COMPRESS_TIME,
"compress");
}
void icetTimingCompressEnd(void)
{
icetTimingEnd(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_COMPRESS_TIME,
"compress");
}
void icetTimingBlendBegin(void)
{
icetTimingBegin(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BLEND_TIME,
"blend");
}
void icetTimingBlendEnd(void)
{
icetTimingEnd(ICET_SUBFUNC_START_TIME,
ICET_SUBFUNC_TIME_ID,
ICET_BLEND_TIME,
"blend");
}
void icetTimingDrawFrameBegin(void)
{
icetTimingBegin(ICET_DRAW_START_TIME,
ICET_DRAW_TIME_ID,
ICET_TOTAL_DRAW_TIME,
"draw frame");
}
void icetTimingDrawFrameEnd(void)
{
icetTimingEnd(ICET_DRAW_START_TIME,
ICET_DRAW_TIME_ID,
ICET_TOTAL_DRAW_TIME,
"draw frame");
}
......@@ -314,7 +314,12 @@ ICET_EXPORT void icetDiagnostics(IceTBitField mask);
#define ICET_BLEND_TIME ICET_COMPARE_TIME
#define ICET_COMPOSITE_TIME (ICET_STATE_TIMING_START | (IceTEnum)0x0006)
#define ICET_TOTAL_DRAW_TIME (ICET_STATE_TIMING_START | (IceTEnum)0x0007)
#define ICET_BYTES_SENT (ICET_STATE_TIMING_START | (IceTEnum)0x0010)
#define ICET_BYTES_SENT (ICET_STATE_TIMING_START | (IceTEnum)0x0008)
#define ICET_DRAW_START_TIME (ICET_STATE_TIMING_START | (IceTEnum)0x0010)
#define ICET_DRAW_TIME_ID (ICET_STATE_TIMING_START | (IceTEnum)0x0011)
#define ICET_SUBFUNC_START_TIME (ICET_STATE_TIMING_START | (IceTEnum)0x0012)
#define ICET_SUBFUNC_TIME_ID (ICET_STATE_TIMING_START | (IceTEnum)0x0013)
/* This set of state variables are reserved for the rendering layer. */
#define ICET_RENDER_LAYER_STATE_START (IceTEnum)0x00000100
......
......@@ -79,8 +79,6 @@ ICET_EXPORT IceTVoid *icetGetStateBuffer(IceTEnum pname,
ICET_EXPORT IceTTimeStamp icetGetTimeStamp(void);
void icetStateResetTiming(void);
void icetStateDump(void);
#ifdef __cplusplus
......
/* -*- c -*- *******************************************************/
/*
* Copyright (C) 2011 Sandia Corporation
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* This source code is released under the New BSD License.
*/
#ifndef __IceTDevTiming_h
#define __IceTDevTiming_h
#include <IceT.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
}
#endif
ICET_EXPORT void icetStateResetTiming(void);
ICET_EXPORT void icetTimingRenderBegin(void);
ICET_EXPORT void icetTimingRenderEnd(void);
ICET_EXPORT void icetTimingBufferReadBegin(void);
ICET_EXPORT void icetTimingBufferReadEnd(void);
ICET_EXPORT void icetTimingBufferWriteBegin(void);
ICET_EXPORT void icetTimingBufferWriteEnd(void);
ICET_EXPORT void icetTimingCompressBegin(void);
ICET_EXPORT void icetTimingCompressEnd(void);
ICET_EXPORT void icetTimingBlendBegin(void);
ICET_EXPORT void icetTimingBlendEnd(void);
ICET_EXPORT void icetTimingDrawFrameBegin(void);
ICET_EXPORT void icetTimingDrawFrameEnd(void);
#ifdef __cplusplus
}
#endif
#endif /* __IceTDevTiming_h */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment