1 /*
2  * stats.c
3  *
4  * Copyright (C) 1989, 1991, Craig E. Kolb
5  * All rights reserved.
6  *
7  * This software may be freely copied, modified, and redistributed
8  * provided that this copyright notice is preserved on all copies.
9  *
10  * You may not distribute this software, in whole or in part, as part of
11  * any commercial product without the express consent of the authors.
12  *
13  * There is no warranty or other guarantee of fitness of this software
14  * for any purpose.  It is provided solely "as is".
15  *
16  * $Id: stats.c,v 4.0 91/07/17 14:47:41 kolb Exp Locker: kolb $
17  *
18  * $Log:	stats.c,v $
19  * Revision 4.0  91/07/17  14:47:41  kolb
20  * Initial version.
21  *
22  */
23 #include <ctype.h>
24 #include "rayshade.h"
25 #include "options.h"
26 #include "stats.h"
27 
28 RSStats Stats;			/* Statistical information */
29 Geom *GeomRep = NULL;	/* Linked list of object representatives */
30 
31 static void PrintGeomStats();
32 
33 void
StatsPrint()34 StatsPrint()
35 {
36 	extern void PrintMemoryStats();
37 	unsigned long TotalRays;
38 
39 #ifndef LINDA
40 	RSGetCpuTime(&Stats.Utime, &Stats.Stime);
41 #endif
42 	ShadowStats(&Stats.ShadowRays, &Stats.ShadowHits,
43 		    &Stats.CacheHits, &Stats.CacheMisses);
44 	IntersectStats(&Stats.BVTests);
45 
46 	TotalRays = Stats.EyeRays + Stats.ShadowRays + Stats.ReflectRays
47 			 + Stats.RefractRays;
48 	Stats.ShadowHits += Stats.CacheHits;
49 	Stats.HitRays += Stats.ShadowHits;
50 #ifdef LINDA
51 	fprintf(Stats.fstats,"Workers:\t\t\t%d\n",Options.workers);
52 #endif
53 	fprintf(Stats.fstats,"Eye rays:\t\t\t%lu\n", Stats.EyeRays);
54 	fprintf(Stats.fstats,"Shadow rays:\t\t\t%lu\n",Stats.ShadowRays);
55 	fprintf(Stats.fstats,"Reflected rays:\t\t\t%lu\n",Stats.ReflectRays);
56 	fprintf(Stats.fstats,"Refracted rays:\t\t\t%lu\n",Stats.RefractRays);
57 	fprintf(Stats.fstats,"Total rays:\t\t\t%lu\n", TotalRays);
58 	if (TotalRays != 0)
59 		fprintf(Stats.fstats,"Intersecting rays:\t\t%lu (%3.3f%%)\n",
60 			Stats.HitRays,
61 			100. * (float)Stats.HitRays / (float)TotalRays);
62 	if (Stats.ShadowRays != 0) {
63 		if (Options.cache)
64 			fprintf(Stats.fstats,
65 				"Shadow cache hits:\t\t%lu (%lu misses)\n",
66 				Stats.CacheHits, Stats.CacheMisses);
67 		fprintf(Stats.fstats,"Total shadow hits:\t\t%lu (%3.3f%%)\n",
68 			Stats.ShadowHits, 100.*(float)Stats.ShadowHits /
69 			(float)Stats.ShadowRays);
70 	}
71 	fprintf(Stats.fstats,"Supersampled pixels:\t\t%lu\n",
72 		Stats.SuperSampled);
73 	fprintf(Stats.fstats,"B.V. intersection tests:\t%lu\n",Stats.BVTests);
74 	PrintGeomStats();
75 #ifdef LINDA
76 	fprintf(Stats.fstats,"Average CPU time/processor:\t");
77 #else
78 	fprintf(Stats.fstats,"Total CPU time (sec):\t\t");
79 #endif
80 	fprintf(Stats.fstats,"%2.2f (%2.2fu + %2.2fs)\n",
81 		Stats.Utime+Stats.Stime, Stats.Utime, Stats.Stime);
82 	if (TotalRays != 0.)
83 		fprintf(Stats.fstats,"Seconds / ray:\t\t\t%4.4f\n",
84 			(Stats.Utime + Stats.Stime) / (Float)TotalRays);
85 	if (Stats.HitRays != 0.)
86 		fprintf(Stats.fstats,"Seconds / intersecting ray:\t%4.4f\n",
87 			(Stats.Utime + Stats.Stime)/(Float)Stats.HitRays);
88 	PrintMemoryStats(Stats.fstats);
89 }
90 
91 static void
PrintGeomStats()92 PrintGeomStats()
93 {
94 	Geom *otmp;
95 	unsigned long tests, hits, totaltests, totalhits;
96 	char *name;
97 	extern void GeomStats();
98 
99 	totaltests = totalhits = 0;
100 
101 	for (otmp = GeomRep; otmp; otmp = otmp->next) {
102 		GeomStats(otmp, &tests, &hits);
103 		if (tests <= 0)
104 			continue;
105 		name = GeomName(otmp);
106 		fprintf(Stats.fstats,
107 			"%c%s intersection tests:\t%lu (%lu hit, %f%%)\n",
108 				toupper((int)name[0]), &name[1], tests, hits,
109 				100.*(float)hits/(float)tests);
110 		if (!IsAggregate(otmp)) {
111 			totaltests += tests;
112 			totalhits += hits;
113 		}
114 	}
115 	fprintf(Stats.fstats,"Total prim. intersection tests:\t%lu",
116 		totaltests);
117 	if (totaltests == 0)
118 		fprintf(Stats.fstats,"\n");
119 	else
120 		fprintf(Stats.fstats," (%lu hit, %f%%)\n", totalhits,
121 			100.*(float)totalhits/(float)totaltests);
122 }
123 
124 void
StatsAddRep(obj)125 StatsAddRep(obj)
126 Geom *obj;
127 {
128 	Geom *otmp;
129 
130 	for (otmp = GeomRep; otmp; otmp = otmp->next) {
131 		if (otmp->methods->stats == obj->methods->stats)
132 			return;
133 	}
134 
135 	/*
136 	 * Stats method didn't match anything found so far.  Add
137 	 * a copy of obj to head of GeomRep list.
138 	 */
139 	otmp = GeomCopy(obj);
140 	otmp->next = GeomRep;
141 	GeomRep = otmp;
142 }
143