rename cl_timeframes to demo_timeframes and make it /not/ archive.

move call to CL_TimeFrames_AddTimestamp from cl_main.c to cl_demo.c.

add a hacky little python script to create a pnm (portable anymap file
format) graph from timeframes.txt
This commit is contained in:
Bill Currie 2003-08-12 06:33:13 +00:00
parent 0a0f8d0cfa
commit b3f99a70be
4 changed files with 136 additions and 40 deletions

View file

@ -43,9 +43,6 @@ void CL_ReRecord_f (void);
void CL_PlayDemo_f (void);
void CL_TimeDemo_f (void);
void CL_TimeFrames_Reset (void);
void CL_TimeFrames_AddTimestamp (void);
void CL_Demo_Init (void);
extern struct cvar_s *demo_speed;

View file

@ -68,12 +68,12 @@ typedef struct {
double fps;
} td_stats_t;
int cl_timeframes_isactive;
int cl_timeframes_index;
int demo_timeframes_isactive;
int demo_timeframes_index;
int demotime_cached;
float nextdemotime;
char demoname[1024];
double *cl_timeframes_array;
double *demo_timeframes_array;
#define CL_TIMEFRAMES_ARRAYBLOCK 4096
int timedemo_count;
@ -83,10 +83,13 @@ td_stats_t *timedemo_data;
static void CL_FinishTimeDemo (void);
static void CL_TimeFrames_DumpLog (void);
static void CL_TimeFrames_AddTimestamp (void);
static void CL_TimeFrames_Reset (void);
cvar_t *demo_speed;
cvar_t *demo_gzip;
cvar_t *demo_quit;
cvar_t *demo_timeframes;
/*
DEMO CODE
@ -401,8 +404,14 @@ readit:
qboolean
CL_GetMessage (void)
{
if (cls.demoplayback)
return CL_GetDemoMessage ();
if (cls.demoplayback) {
qboolean ret = CL_GetDemoMessage ();
if (!ret && demo_timeframes_isactive) {
CL_TimeFrames_AddTimestamp ();
}
return ret;
}
if (!NET_GetPacket ())
return false;
@ -943,8 +952,8 @@ CL_StartTimeDemo (void)
cls.td_lastframe = -1; // get a new message this frame
CL_TimeFrames_Reset ();
if (cl_timeframes->int_val)
cl_timeframes_isactive = 1;
if (demo_timeframes->int_val)
demo_timeframes_isactive = 1;
}
static inline double
@ -970,7 +979,7 @@ CL_FinishTimeDemo (void)
frames / time);
CL_TimeFrames_DumpLog ();
cl_timeframes_isactive = 0;
demo_timeframes_isactive = 0;
timedemo_count--;
timedemo_data[timedemo_count].frames = time;
@ -1039,9 +1048,9 @@ CL_TimeDemo_f (void)
void
CL_Demo_Init (void)
{
cl_timeframes_isactive = 0;
cl_timeframes_index = 0;
cl_timeframes_array = NULL;
demo_timeframes_isactive = 0;
demo_timeframes_index = 0;
demo_timeframes_array = NULL;
demo_gzip = Cvar_Get ("demo_gzip", "0", CVAR_ARCHIVE, NULL,
"Compress demos using gzip. 0 = none, 1 = least "
@ -1052,31 +1061,30 @@ CL_Demo_Init (void)
"< 1 slow-mo, > 1 timelapse");
demo_quit = Cvar_Get ("demo_quit", "0", CVAR_NONE, NULL,
"automaticly quit after a timedemo has finished");
demo_timeframes = Cvar_Get ("demo_timeframes", "0", CVAR_NONE, NULL,
"write timestamps for every frame");
}
void
static void
CL_TimeFrames_Reset (void)
{
cl_timeframes_index = 0;
free (cl_timeframes_array);
cl_timeframes_array = NULL;
demo_timeframes_index = 0;
free (demo_timeframes_array);
demo_timeframes_array = NULL;
}
void
static void
CL_TimeFrames_AddTimestamp (void)
{
if (cl_timeframes_isactive) {
if (!(cl_timeframes_index % CL_TIMEFRAMES_ARRAYBLOCK))
cl_timeframes_array = realloc
(cl_timeframes_array, sizeof (cl_timeframes_array[0]) *
((cl_timeframes_index / CL_TIMEFRAMES_ARRAYBLOCK) + 1) *
CL_TIMEFRAMES_ARRAYBLOCK);
if (cl_timeframes_array == NULL)
Sys_Error ("Unable to allocate timeframes buffer");
cl_timeframes_array[cl_timeframes_index] = Sys_DoubleTime ();
cl_timeframes_index++;
}
return;
if (!(demo_timeframes_index % CL_TIMEFRAMES_ARRAYBLOCK))
demo_timeframes_array = realloc
(demo_timeframes_array, sizeof (demo_timeframes_array[0]) *
((demo_timeframes_index / CL_TIMEFRAMES_ARRAYBLOCK) + 1) *
CL_TIMEFRAMES_ARRAYBLOCK);
if (demo_timeframes_array == NULL)
Sys_Error ("Unable to allocate timeframes buffer");
demo_timeframes_array[demo_timeframes_index] = Sys_DoubleTime ();
demo_timeframes_index++;
}
static void
@ -1087,7 +1095,7 @@ CL_TimeFrames_DumpLog (void)
long frame;
QFile *outputfile;
if (cl_timeframes_isactive == 0)
if (demo_timeframes_isactive == 0)
return;
Con_Printf ("Dumping Timed Frames log: %s\n", filename);
@ -1096,8 +1104,8 @@ CL_TimeFrames_DumpLog (void)
Con_Printf ("Could not open: %s\n", filename);
return;
}
for (i = 1; i < cl_timeframes_index; i++) {
frame = (cl_timeframes_array[i] - cl_timeframes_array[i - 1]) * 1e6;
for (i = 1; i < demo_timeframes_index; i++) {
frame = (demo_timeframes_array[i] - demo_timeframes_array[i - 1]) * 1e6;
Qprintf (outputfile, "%09ld\n", frame);
}
Qclose (outputfile);

View file

@ -135,8 +135,6 @@ cvar_t *cl_writecfg;
cvar_t *cl_allow_cmd_pkt;
cvar_t *cl_paranoid;
cvar_t *cl_timeframes;
cvar_t *cl_timeout;
cvar_t *cl_shownet;
@ -1277,8 +1275,6 @@ CL_Init_Cvars (void)
localid = Cvar_Get ("localid", "", CVAR_NONE, NULL, "Used by "
"gamespy+others to authenticate when sending "
"commands to the client");
cl_timeframes = Cvar_Get ("cl_timeframes", "0", CVAR_ARCHIVE, NULL,
"write timestamps for every frame");
// info mirrors
cl_name = Cvar_Get ("name", "unnamed", CVAR_ARCHIVE | CVAR_USERINFO,
Cvar_Info, "Player name");
@ -1556,8 +1552,6 @@ Host_Frame (float time)
pass1 + pass2 + pass3, pass1, pass2, pass3);
}
// CL_TimeFrames_AddTimestamp ();
host_framecount++;
fps_count++;
}

97
tools/misc/timeframes.py Normal file
View file

@ -0,0 +1,97 @@
import array
black = ( 0, 0, 0)
blue = ( 0, 0,255)
green = ( 0,255, 0)
cyan = ( 0,255,255)
red = (255, 0, 0)
magenta = (255, 0,255)
yellow = (255,255, 0)
white = (255,255, 0)
def plot (x, y, color):
y = height - 1 - y
p = (y * width + x) * 3
a[p + 0], a[p + 1], a[p + 2] = color
def vline (x, y1, y2, color):
if y1 == y2:
plot (x, y1, color)
elif y1 < y2:
for y in range (y1, y2 + 1):
plot (x, y, color)
else:
for y in range (y2, y1 + 1):
plot (x, y, color)
def hline (x1, x2, y, color):
if x1 == x2:
plot (x1, y, color)
elif x1 < x2:
for x in range (x1, x2 + 1):
plot (x, y, color)
else:
for x in range (x2, x1 + 1):
plot (x, y, color)
f = open ("timeframes.txt", "rt")
lines = f.readlines ()
f.close
times = map (lambda x: (int(x) + 5)/100, lines[2:])
sum = 0
min=max=times[0]
for t in times:
if min > t:
min = t
if max < t:
max = t
sum = sum + t
print min/10.0, max/10.0, sum/10.0 / len(times)
average = sum / len(times)
group = 1
width = (len (times) + group - 1) / group
height = max + 1
a = array.array ('B', '\0' * height * width * 3)
ravg = 0.0
ravg_span = 20
for x in range (width):
if group > 1:
tset = times[x * group: x * group + group]
sum = 0;
min = max = tset[0]
for t in tset:
if min > t:
min = t
if max < t:
max = t
sum = sum + t
if x:
oldavg = avg
avg = sum / len (tset)
vline (x, min, max, green)
if x:
vline (x, oldavg, avg, yellow)
else:
plot (x, avg, yellow)
else:
if x < width - 1:
vline (x, times[x], times[x + 1], yellow)
plot (x, times[x], red)
plot (x, int (ravg + 0.5), cyan)
if (x >= ravg_span):
ravg -= times[x - ravg_span]/float(ravg_span)
ravg += times[x]/float(ravg_span)
hline (0, width - 1, average, blue)
f = open ("timeframes.ppm", "wb")
f.write ("P6\n")
f.write ("#File written by timeframes.py\n")
f.write (`width` + " " + `height` + "\n")
f.write ("255\n")
f.write (a.tostring ())
f.close ()