Optimizing realtime vis.

This commit is contained in:
Federico Ponchio 2004-12-15 13:50:32 +00:00
parent e8c748d159
commit b2f3d4f49e
9 changed files with 161 additions and 158 deletions

View File

@ -29,9 +29,9 @@ class LruPServer: public PServer {
return *((*i).second); return *((*i).second);
} else { } else {
while(ram_used > ram_max) { while(ram_used > ram_max) {
index.erase(items.back().first); index.erase(items.back().first);
FlushPatch(patch, items.back().second); FlushPatch(patch, items.back().second);
items.pop_back(); items.pop_back();
} }
Item item; Item item;
item.first = patch; item.first = patch;
@ -46,13 +46,14 @@ class LruPServer: public PServer {
bool IsLoaded(unsigned int patch) { bool IsLoaded(unsigned int patch) {
return index.count(patch); return index.count(patch);
} }
void Flush() { void Flush() {
std::cerr << "Lru flulshing\n";
std::map<unsigned int, Items::iterator>::iterator i; std::map<unsigned int, Items::iterator>::iterator i;
for(i = index.begin(); i != index.end(); i++) { for(i = index.begin(); i != index.end(); i++) {
Item &item = *((*i).second); Item &item = *((*i).second);
FlushPatch((*i).first, item.second); FlushPatch((*i).first, item.second);
} }
for(int k = 0; k < entries.size(); k++)
entries[k].patch = NULL;
items.clear(); items.clear();
index.clear(); index.clear();

View File

@ -215,9 +215,9 @@ bool NexusMt::InitGL(Vbo mode, unsigned int vbosize) {
cerr << "No vbo available!" << endl; cerr << "No vbo available!" << endl;
vbo_mode = VBO_OFF; vbo_mode = VBO_OFF;
} }
patches.vbo_max = vbosize / chunk_size; /*WORKING? patches.vbo_max = vbosize / chunk_size;
if(vbo_mode == VBO_OFF) if(vbo_mode == VBO_OFF)
patches.vbo_max = 0; patches.vbo_max = 0;*/
prefetch.start(); prefetch.start();
return true; return true;
@ -381,7 +381,7 @@ void NexusMt::SetError(float error) {
} }
void NexusMt::SetVboSize(unsigned int _vbo_max) { void NexusMt::SetVboSize(unsigned int _vbo_max) {
patches.vbo_max = _vbo_max; //WORKING patches.vbo_max = _vbo_max;
} }
void NexusMt::SetPrefetchSize(unsigned int size) { void NexusMt::SetPrefetchSize(unsigned int size) {
@ -443,14 +443,16 @@ void NexusMt::LoadHistory() {
Node &node = nodes[current_node]; Node &node = nodes[current_node];
node.error = 0; node.error = 0;
//cerr << "Created: ";
//created cells belong to this node, we look also for max error. //created cells belong to this node, we look also for max error.
for(unsigned int i = 0; i < (*u).created.size(); i++) { for(unsigned int i = 0; i < (*u).created.size(); i++) {
unsigned int cell = (*u).created[i]; unsigned int cell = (*u).created[i];
//cerr << cell << " ";
if(index[cell].error > node.error) if(index[cell].error > node.error)
node.error = index[cell].error; node.error = index[cell].error;
cell_node[cell] = current_node; cell_node[cell] = current_node;
} }
//cerr << endl;
//Every erased cell already belonged to a node. //Every erased cell already belonged to a node.
//we record for each node its cells. //we record for each node its cells.

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.25 2004/12/15 08:46:16 ponchio
Optimizing realtime vis.
Revision 1.24 2004/12/13 00:44:48 ponchio Revision 1.24 2004/12/13 00:44:48 ponchio
Lotsa changes... Lotsa changes...
@ -259,9 +262,14 @@ int main(int argc, char *argv[]) {
float alpha = 0; float alpha = 0;
bool redraw = false; bool redraw = false;
float fps = 0; float fps = 0;
float tframe = 0; unsigned int nave = 5;
unsigned int offset = 0;
vector<float> tframe;
for(int i = 0; i < 5; i++) tframe.push_back(0);
bool keepdrawing = true; bool keepdrawing = true;
watch.Start();
while( !quit ) { while( !quit ) {
unsigned int anything = SDL_PollEvent(&event); unsigned int anything = SDL_PollEvent(&event);
if(!anything && !keepdrawing) { if(!anything && !keepdrawing) {
@ -281,12 +289,12 @@ int main(int argc, char *argv[]) {
case SDLK_c: show_colors = !show_colors; break; case SDLK_c: show_colors = !show_colors; break;
case SDLK_n: show_normals = !show_normals; break; case SDLK_n: show_normals = !show_normals; break;
case SDLK_LEFT: nexus.extraction_max *= 0.7; break; case SDLK_LEFT: nexus.patches.ram_max *= 0.8; break;
case SDLK_RIGHT: nexus.extraction_max *= 1.5; break; case SDLK_RIGHT: nexus.patches.ram_max *= 1.3; break;
case SDLK_UP: nexus.draw_max *= 1.5; break; case SDLK_UP: nexus.draw_max *= 1.3; break;
case SDLK_DOWN: nexus.draw_max *= 0.7; break; case SDLK_DOWN: nexus.draw_max *= 0.8; break;
case SDLK_PAGEUP: nexus.disk_max *= 1.5; break; case SDLK_PAGEUP: nexus.disk_max *= 1.3; break;
case SDLK_PAGEDOWN: nexus.disk_max *= 0.7; break; case SDLK_PAGEDOWN: nexus.disk_max *= 0.8; break;
case SDLK_s: metric = NexusMt::FRUSTUM; break; case SDLK_s: metric = NexusMt::FRUSTUM; break;
case SDLK_p: mode = NexusMt::POINTS; nexus.SetMode(mode); break; case SDLK_p: mode = NexusMt::POINTS; nexus.SetMode(mode); break;
@ -394,7 +402,7 @@ int main(int argc, char *argv[]) {
nexus.SetComponent(NexusMt::NORMAL, show_normals); nexus.SetComponent(NexusMt::NORMAL, show_normals);
static vector<unsigned int> cells; static vector<unsigned int> cells;
watch.Start(); //watch.Start();
if(extract) { if(extract) {
// nexus.patches.Flush(); // nexus.patches.Flush();
@ -439,18 +447,19 @@ int main(int argc, char *argv[]) {
char buffer[1024]; char buffer[1024];
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
double ftime = (tframe[(offset+4)%5] - tframe[(offset)%5])/5.0f;
/* sprintf(buffer, "Ram size : %.3fMb (max) %.3fMb (cur)", /* sprintf(buffer, "Ram size : %.3fMb (max) %.3fMb (cur)",
nexus.patches->ram_size * nexus.chunk_size/(float)(1<<20), nexus.patches->ram_size * nexus.chunk_size/(float)(1<<20),
nexus.patches->ram_used * nexus.chunk_size/(float)(1<<20)); nexus.patches->ram_used * nexus.chunk_size/(float)(1<<20));
gl_print(0.03, 0.12, buffer);*/ gl_print(0.03, 0.12, buffer);*/
sprintf(buffer, "Extr size: %.3fMb(max) %.3fMb(cur)", sprintf(buffer, "Ram size: %.3fMb(max) %.3fMb(cur)",
nexus.patches.ram_max * nexus.chunk_size/(float)(1<<20), nexus.patches.ram_max * nexus.chunk_size/(float)(1<<20),
nexus.patches.ram_used * nexus.chunk_size/(float)(1<<20)); nexus.patches.ram_used * nexus.chunk_size/(float)(1<<20));
gl_print(0.03, 0.09, buffer); gl_print(0.03, 0.09, buffer);
sprintf(buffer, "Vbo size : %.3fMb(max) %.3fMb(cur)", sprintf(buffer, "Vbo size : %.3fMb(cur)",
nexus.patches.vbo_max * nexus.chunk_size/(float)(1<<20),
nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20)); nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20));
gl_print(0.03, 0.06, buffer); gl_print(0.03, 0.06, buffer);
@ -458,7 +467,7 @@ int main(int argc, char *argv[]) {
"%.3f time %.2f FPS", "%.3f time %.2f FPS",
nexus.tri_total/(float)(1<<10), nexus.tri_total/(float)(1<<10),
nexus.tri_rendered/(float)(1<<10), nexus.tri_rendered/(float)(1<<10),
tframe, 1/tframe); ftime, 1/ftime);
gl_print(0.03, 0.03, buffer); gl_print(0.03, 0.03, buffer);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -469,7 +478,7 @@ int main(int argc, char *argv[]) {
} }
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
tframe = watch.Time(); tframe[offset++%5] = watch.Time();
} }

View File

@ -31,11 +31,17 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
notloaded++; notloaded++;
} else { } else {
PatchInfo &info = mt->index[patch]; PatchInfo &info = mt->index[patch];
QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, 0.0f, flush); //WORKING QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, 0.0f, flush);
if(flush.size() != 0) { QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, flush);
for(unsigned int i = 0; i < flush.size(); i++) {
QueuePServer::Data *data = new QueuePServer::Data;
*data = flush[i];
draw.post(QueuePServer::FLUSH, (unsigned int)data);
}
/* WORKING if(flush.size() != 0) {
cerr << "Flushing!\n"; cerr << "Flushing!\n";
exit(0); exit(0);
} } */
mt->todraw.push_back(&data); mt->todraw.push_back(&data);
} }
//missing.push_back(PServer::Item(patch, 0.0f)); //missing.push_back(PServer::Item(patch, 0.0f));
@ -52,7 +58,7 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
missing.push_back(item); missing.push_back(item);
} }
QueuePServer &ps = mt->patches; /* WORKING QueuePServer &ps = mt->patches;
for(unsigned int i = 0; i < ps.heap.size(); i++) { for(unsigned int i = 0; i < ps.heap.size(); i++) {
PServer::Item &item = ps.heap[i]; PServer::Item &item = ps.heap[i];
if(tmp.count(item.patch)) if(tmp.count(item.patch))
@ -61,14 +67,9 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
if(item.priority == 0) if(item.priority == 0)
item.priority = 1; item.priority = 1;
item.priority *= 1.1; item.priority *= 1.1;
} }
/*if(tmp.count(item.patch))
item.priority = tmp[item.patch];
else
item.priority = 1e30;*/
} }
make_heap(ps.heap.begin(), ps.heap.end()); make_heap(ps.heap.begin(), ps.heap.end());*/
sort(missing.begin(), missing.end()); //CRITICAL reverse pero'! sort(missing.begin(), missing.end()); //CRITICAL reverse pero'!
reverse(missing.begin(), missing.end()); reverse(missing.begin(), missing.end());
@ -77,19 +78,25 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
safety.unlock(); safety.unlock();
} }
void Prefetch::execute() { void Prefetch::execute() {
unsigned int prefetched = 0;
while(1) { while(1) {
if(get_signaled()) return; if(get_signaled()) return;
vector<QueuePServer::Data> flush; vector<QueuePServer::Data> flush;
if(load.get_count() || missing.size() == 0) { if(load.get_count() || missing.size() == 0) {
if(prefetched)
cerr << "Prefetched: " << prefetched << endl;
prefetched = 0;
pt::message *msg = load.getmessage(); pt::message *msg = load.getmessage();
if(msg->id != 0xffffffff) { if(msg->id != 0xffffffff) {
safety.lock(); safety.lock();
PatchInfo &info = mt->index[msg->id]; PatchInfo &info = mt->index[msg->id];
//posting draw message //posting draw message
QueuePServer::Data &data = mt->patches.Lookup(msg->id, info.nvert, info.nface, 0.0f, flush); //WORKING QueuePServer::Data &data = mt->patches.Lookup(msg->id, info.nvert, info.nface, 0.0f, flush);
QueuePServer::Data &data = mt->patches.Lookup(msg->id, info.nvert, info.nface, flush);
pt::message *msg = new pt::message(QueuePServer::DRAW, (unsigned int)&data); pt::message *msg = new pt::message(QueuePServer::DRAW, (unsigned int)&data);
msg->result = msg->id; msg->result = msg->id;
draw.post(msg); draw.post(msg);
@ -109,19 +116,23 @@ void Prefetch::execute() {
PServer::Item item = missing.back(); PServer::Item item = missing.back();
missing.pop_back(); missing.pop_back();
if(item.priority > mt->patches.MaxPriority()) { /*Working if(item.priority > mt->patches.MaxPriority()) {
missing.clear(); missing.clear();
} else { } else { */
PatchInfo &info = mt->index[item.patch]; PatchInfo &info = mt->index[item.patch];
//cerr << "prefetching: " << item.patch << endl; //cerr << "prefetching: " << item.patch << endl;
mt->patches.Lookup(item.patch, info.nvert, info.nface, item.priority, flush); //WORKING mt->patches.Lookup(item.patch, info.nvert, info.nface, item.priority, flush);
for(unsigned int i = 0; i < flush.size(); i++) { if(!mt->patches.entries[item.patch].patch) {
QueuePServer::Data *data = new QueuePServer::Data; mt->patches.Lookup(item.patch, info.nvert, info.nface, flush);
*data = flush[i]; prefetched++;
draw.post(QueuePServer::FLUSH, (unsigned int)data); for(unsigned int i = 0; i < flush.size(); i++) {
QueuePServer::Data *data = new QueuePServer::Data;
*data = flush[i];
draw.post(QueuePServer::FLUSH, (unsigned int)data);
}
} }
} // }
} }
safety.unlock(); safety.unlock();
} }

View File

@ -66,6 +66,7 @@ void PServer::AddPatch(unsigned short nvert, unsigned short nface) {
entry.patch_start = 0xffffffff; entry.patch_start = 0xffffffff;
entry.ram_size = Patch::ChunkSize(signature, nvert, nface, chunk_size); entry.ram_size = Patch::ChunkSize(signature, nvert, nface, chunk_size);
entry.disk_size = 0xffff; entry.disk_size = 0xffff;
entry.patch = NULL;
entries.push_back(entry); entries.push_back(entry);
} }
@ -79,7 +80,7 @@ Patch *PServer::LoadPatch(unsigned int idx,
if(entry.patch) return entry.patch; if(entry.patch) return entry.patch;
char *ram = new char[entry.ram_size * chunk_size]; char *ram = new char[entry.ram_size * chunk_size];
#ifdef CONTROLS #ifndef NDEBUG
if(!ram) { if(!ram) {
cerr << "COuld not allocate ram!\n"; cerr << "COuld not allocate ram!\n";
exit(0); exit(0);

View File

@ -6,7 +6,7 @@ using namespace std;
using namespace nxs; using namespace nxs;
using namespace pt; using namespace pt;
/*
QueuePServer::Data &QueuePServer::Lookup(unsigned int patch, QueuePServer::Data &QueuePServer::Lookup(unsigned int patch,
unsigned short nv, unsigned short nf, unsigned short nv, unsigned short nf,
float priority, float priority,
@ -33,85 +33,12 @@ QueuePServer::Data &QueuePServer::Lookup(unsigned int patch,
// cerr << "Loading: " << patch << endl; // cerr << "Loading: " << patch << endl;
data.patch = LoadPatch(patch, nv, nf); data.patch = LoadPatch(patch, nv, nf);
/*if(priority == 0) {
message *msg = new message(DRAW, (unsigned int)&data);
msg->result = patch;
queue.post(msg);
} */
return data; return data;
} }
} }
/*
QueuePServer::Data &QueuePServer::Lookup(unsigned int patch,
unsigned short nv, unsigned short nf,
float priority) {
if(index.count(patch)) {
Data &data = index[patch];
if(priority == 0) {
// cerr << "Posting draw!\n";
message *msg = new message(DRAW, (unsigned int)&data);
msg->result = patch;
queue.post(msg);
}
return data;
} else {
while(ram_used > ram_max) {
pop_heap(heap.begin(), heap.end());
Item item = heap.back();
if(item.priority == 0) break; //no deleting needed patches.
// cerr << "Dropping: " << item.patch << endl;
Data &data = index[item.patch];
FlushVbo(data);
Data *d = new Data(data);
queue.post(FLUSH, (unsigned int)d);
FlushPatch(item.patch, data.patch);
index.erase(item.patch);
}
Item item(patch, priority);
heap.push_back(item);
push_heap(heap.begin(), heap.end());
Data &data = index[patch];
// cerr << "Loading: " << patch << endl;
data.patch = LoadPatch(patch, nv, nf);
if(priority == 0) {
message *msg = new message(DRAW, (unsigned int)&data);
msg->result = patch;
queue.post(msg);
}
return data;
}
}
*/
/*QueuePServer::Data &QueuePServer::Lookup(unsigned int patch,
Patch *mem,
float priority) {
if(index.count(patch)) {
Data &data = index[patch];
return data;
} else {
while(ram_used > ram_max) {
pop_heap(heap.begin(), heap.end());
Item item = heap.back();
if(item.priority == 0) break; //no deleting needed patches.
// cerr << "Dropping: " << item.patch << endl;
Data &data = index[item.patch];
FlushVbo(data);
FlushPatch(item.patch, data.patch);
index.erase(item.patch);
}
Item item(patch, priority);
heap.push_back(item);
push_heap(heap.begin(), heap.end());
Data &data = index[patch];
// cerr << "Loading: " << patch << endl;
data.patch = mem;
LoadVbo(data);
return data;
}
} */
bool QueuePServer::IsLoaded(unsigned int patch) { bool QueuePServer::IsLoaded(unsigned int patch) {
return index.count(patch); return index.count(patch);
@ -128,10 +55,10 @@ void QueuePServer::Flush() {
FlushVbo((*i).second); FlushVbo((*i).second);
FlushPatch((*i).first, (*i).second.patch); FlushPatch((*i).first, (*i).second.patch);
} }
} } */
void QueuePServer::LoadVbo(Data &data) { void QueuePServer::LoadVbo(Data &data) {
if(!vbo_max) return; //WORKING if(!vbo_max) return;
Patch &patch = *data.patch; Patch &patch = *data.patch;
glGenBuffersARB(1, &data.vbo_element); glGenBuffersARB(1, &data.vbo_element);
assert(data.vbo_element); assert(data.vbo_element);
@ -157,7 +84,7 @@ void QueuePServer::LoadVbo(Data &data) {
vbo_used += size; vbo_used += size;
} }
void QueuePServer::FlushVbo(Data &data) { void QueuePServer::FlushVbo(Data &data) {
if(!vbo_max) return; //WORKING if(!vbo_max) return;
if(!data.vbo_element) return; if(!data.vbo_element) return;
//glDeleteBuffersARB(1, &data.vbo_element); //glDeleteBuffersARB(1, &data.vbo_element);
//glDeleteBuffersARB(1, &data.vbo_array); //glDeleteBuffersARB(1, &data.vbo_array);

View File

@ -12,6 +12,7 @@
namespace nxs { namespace nxs {
class QueuePServer: public PServer { class QueuePServer: public PServer {
public: public:
@ -23,27 +24,72 @@ class QueuePServer: public PServer {
Data(): patch(NULL), vbo_array(0), vbo_element(0) {} Data(): patch(NULL), vbo_array(0), vbo_element(0) {}
}; };
pt::jobqueue queue; pt::jobqueue queue;
unsigned int vbo_used; unsigned int vbo_used;
unsigned int vbo_max;
std::map<unsigned int, Data> index; typedef std::pair<unsigned int, Data> Item;
std::vector<Item> heap; std::list<Item> items;
typedef std::list<Item> Items;
QueuePServer(): queue(64000) {} std::map<unsigned int, Items::iterator> index;
//Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, QueuePServer(): queue(64000), vbo_used(0) {}
// float priority = 0.0f); ~QueuePServer() {
Flush();
}
Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf,
std::vector<Data> &flush) {
if(index.count(patch)) {
Items::iterator &i = index[patch];
Item item = *i;
items.erase(i);
items.push_front(item);
i = items.begin();
return ((*i).second);
} else {
while(ram_used > ram_max) {
Data &data = items.back().second;
//TODO i should not flush current extraction!
index.erase(items.back().first);
FlushPatch(patch, data.patch);
flush.push_back(data);
items.pop_back();
}
Item item;
item.first = patch;
item.second.patch = LoadPatch(patch, nv, nf);
items.push_front(item);
Items::iterator i = items.begin();
index[patch] = i;
return ((*i).second);
}
}
//return flushing too. //return flushing too.
Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, float priority, //Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, float priority,
std::vector<QueuePServer::Data> &data); // std::vector<QueuePServer::Data> &data);
bool IsLoaded(unsigned int patch);
float MaxPriority();
void Flush();
//bool IsLoaded(unsigned int patch);
//float MaxPriority();
bool IsLoaded(unsigned int patch) {
return index.count(patch);
}
void Flush() {
std::map<unsigned int, Items::iterator>::iterator i;
for(i = index.begin(); i != index.end(); i++) {
Item &item = *((*i).second);
FlushVbo(item.second);
FlushPatch((*i).first, item.second.patch);
}
for(int k = 0; k < entries.size(); k++)
entries[k].patch = NULL;
items.clear();
index.clear();
}
void LoadVbo(Data &data); void LoadVbo(Data &data);
void FlushVbo(Data &data); void FlushVbo(Data &data);
}; };

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.3 2004/10/21 13:40:16 ponchio
Debugging.
Revision 1.2 2004/10/21 12:14:02 ponchio Revision 1.2 2004/10/21 12:14:02 ponchio
Support for mfile (>4Gb) Support for mfile (>4Gb)
@ -61,19 +64,19 @@ void Watch::Start(void) {
elapsed = 0; elapsed = 0;
} }
float Watch::Pause() { double Watch::Pause() {
QueryPerformanceCounter(&tend); QueryPerformanceCounter(&tend);
elapsed += Diff(); elapsed += Diff();
return (float)elapsed; return (double)elapsed;
} }
void Watch::Continue() { void Watch::Continue() {
QueryPerformanceCounter(&tstart); QueryPerformanceCounter(&tstart);
} }
float Watch::Time() { double Watch::Time() {
QueryPerformanceCounter(&tend); QueryPerformanceCounter(&tend);
return (float)(elapsed + Diff()); return (double)(elapsed + Diff());
} }
double Watch::Diff() { double Watch::Diff() {
@ -91,19 +94,19 @@ void Watch::Start() {
elapsed = 0; elapsed = 0;
} }
float Watch::Pause() { double Watch::Pause() {
gettimeofday(&tend, &tz); gettimeofday(&tend, &tz);
elapsed += Diff(); elapsed += Diff();
return (float)elapsed; return (double)elapsed;
} }
void Watch::Continue() { void Watch::Continue() {
gettimeofday(&tstart, &tz); gettimeofday(&tstart, &tz);
} }
float Watch::Time() { double Watch::Time() {
gettimeofday(&tend, &tz); gettimeofday(&tend, &tz);
return (float)(elapsed + Diff()); return (double)(elapsed + Diff());
} }
double Watch::Diff() { double Watch::Diff() {
@ -127,7 +130,7 @@ int Watch::Usec() {
#endif #endif
} }
void Report::Init(unsigned int t, float inter) { void Report::Init(unsigned int t, double inter) {
watch.Start(); watch.Start();
tot = t; tot = t;
last = 0; last = 0;
@ -136,17 +139,17 @@ void Report::Init(unsigned int t, float inter) {
void Report::Step(unsigned int count) { void Report::Step(unsigned int count) {
if(count == 0) return; if(count == 0) return;
float now = watch.Time(); double now = watch.Time();
if(now - last < interval) return; if(now - last < interval) return;
//estimate final time //estimate final time
float tot_time = now * tot/(float)count; double tot_time = now * tot/(double)count;
printf("%d/%d\telapsed: %.1f\tremaining: %.1f\ttotal: %.1f\n", printf("%d/%d\telapsed: %.1f\tremaining: %.1f\ttotal: %.1f\n",
count, tot, now, tot_time - now, tot_time); count, tot, now, tot_time - now, tot_time);
last = now; last = now;
} }
void Report::Finish() { void Report::Finish() {
float now = watch.Time(); double now = watch.Time();
printf("Tot: %.1f\tN: %d\tN/sec: %.1f\n", printf("Tot: %.1f\tN: %d\tN/sec: %.1f\n",
now, tot, tot/now); now, tot, tot/now);
} }

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.5 2004/12/01 16:00:35 ponchio
Level 3
Revision 1.4 2004/11/28 04:10:59 ponchio Revision 1.4 2004/11/28 04:10:59 ponchio
winsockapi include problem winsockapi include problem
@ -65,10 +68,10 @@ class Watch {
public: public:
Watch(); Watch();
void Start(); void Start();
float Pause(); double Pause();
void Continue(); void Continue();
void Reset(); void Reset();
float Time(); double Time();
int Usec(); int Usec();
private: private:
double Diff(); double Diff();
@ -85,13 +88,13 @@ private:
class Report { class Report {
public: public:
Report(unsigned int tot = 1, float inter = 30.0f) { Init(tot, inter); } Report(unsigned int tot = 1, double inter = 30.0f) { Init(tot, inter); }
void Init(unsigned int tot, float inter = 30.0f); void Init(unsigned int tot, double inter = 30.0f);
void Step(unsigned int count); void Step(unsigned int count);
void Finish(); void Finish();
private: private:
Watch watch; Watch watch;
int tot; int tot;
float last; double last;
float interval; double interval;
}; };