Optimizing realtime vis.
This commit is contained in:
parent
e8c748d159
commit
b2f3d4f49e
|
@ -29,9 +29,9 @@ class LruPServer: public PServer {
|
|||
return *((*i).second);
|
||||
} else {
|
||||
while(ram_used > ram_max) {
|
||||
index.erase(items.back().first);
|
||||
FlushPatch(patch, items.back().second);
|
||||
items.pop_back();
|
||||
index.erase(items.back().first);
|
||||
FlushPatch(patch, items.back().second);
|
||||
items.pop_back();
|
||||
}
|
||||
Item item;
|
||||
item.first = patch;
|
||||
|
@ -46,13 +46,14 @@ class LruPServer: public PServer {
|
|||
bool IsLoaded(unsigned int patch) {
|
||||
return index.count(patch);
|
||||
}
|
||||
void Flush() {
|
||||
std::cerr << "Lru flulshing\n";
|
||||
void Flush() {
|
||||
std::map<unsigned int, Items::iterator>::iterator i;
|
||||
for(i = index.begin(); i != index.end(); i++) {
|
||||
Item &item = *((*i).second);
|
||||
FlushPatch((*i).first, item.second);
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < entries.size(); k++)
|
||||
entries[k].patch = NULL;
|
||||
|
||||
items.clear();
|
||||
index.clear();
|
||||
|
|
|
@ -215,9 +215,9 @@ bool NexusMt::InitGL(Vbo mode, unsigned int vbosize) {
|
|||
cerr << "No vbo available!" << endl;
|
||||
vbo_mode = VBO_OFF;
|
||||
}
|
||||
patches.vbo_max = vbosize / chunk_size;
|
||||
/*WORKING? patches.vbo_max = vbosize / chunk_size;
|
||||
if(vbo_mode == VBO_OFF)
|
||||
patches.vbo_max = 0;
|
||||
patches.vbo_max = 0;*/
|
||||
|
||||
prefetch.start();
|
||||
return true;
|
||||
|
@ -381,7 +381,7 @@ void NexusMt::SetError(float error) {
|
|||
}
|
||||
|
||||
void NexusMt::SetVboSize(unsigned int _vbo_max) {
|
||||
patches.vbo_max = _vbo_max;
|
||||
//WORKING patches.vbo_max = _vbo_max;
|
||||
}
|
||||
|
||||
void NexusMt::SetPrefetchSize(unsigned int size) {
|
||||
|
@ -443,14 +443,16 @@ void NexusMt::LoadHistory() {
|
|||
Node &node = nodes[current_node];
|
||||
node.error = 0;
|
||||
|
||||
//cerr << "Created: ";
|
||||
//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];
|
||||
//cerr << cell << " ";
|
||||
if(index[cell].error > node.error)
|
||||
node.error = index[cell].error;
|
||||
|
||||
node.error = index[cell].error;
|
||||
cell_node[cell] = current_node;
|
||||
}
|
||||
//cerr << endl;
|
||||
|
||||
//Every erased cell already belonged to a node.
|
||||
//we record for each node its cells.
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Lotsa changes...
|
||||
|
||||
|
@ -259,9 +262,14 @@ int main(int argc, char *argv[]) {
|
|||
float alpha = 0;
|
||||
bool redraw = false;
|
||||
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;
|
||||
|
||||
watch.Start();
|
||||
while( !quit ) {
|
||||
unsigned int anything = SDL_PollEvent(&event);
|
||||
if(!anything && !keepdrawing) {
|
||||
|
@ -281,12 +289,12 @@ int main(int argc, char *argv[]) {
|
|||
case SDLK_c: show_colors = !show_colors; break;
|
||||
case SDLK_n: show_normals = !show_normals; break;
|
||||
|
||||
case SDLK_LEFT: nexus.extraction_max *= 0.7; break;
|
||||
case SDLK_RIGHT: nexus.extraction_max *= 1.5; break;
|
||||
case SDLK_UP: nexus.draw_max *= 1.5; break;
|
||||
case SDLK_DOWN: nexus.draw_max *= 0.7; break;
|
||||
case SDLK_PAGEUP: nexus.disk_max *= 1.5; break;
|
||||
case SDLK_PAGEDOWN: nexus.disk_max *= 0.7; break;
|
||||
case SDLK_LEFT: nexus.patches.ram_max *= 0.8; break;
|
||||
case SDLK_RIGHT: nexus.patches.ram_max *= 1.3; break;
|
||||
case SDLK_UP: nexus.draw_max *= 1.3; break;
|
||||
case SDLK_DOWN: nexus.draw_max *= 0.8; break;
|
||||
case SDLK_PAGEUP: nexus.disk_max *= 1.3; break;
|
||||
case SDLK_PAGEDOWN: nexus.disk_max *= 0.8; break;
|
||||
|
||||
case SDLK_s: metric = NexusMt::FRUSTUM; 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);
|
||||
|
||||
static vector<unsigned int> cells;
|
||||
watch.Start();
|
||||
//watch.Start();
|
||||
if(extract) {
|
||||
// nexus.patches.Flush();
|
||||
|
||||
|
@ -439,18 +447,19 @@ int main(int argc, char *argv[]) {
|
|||
char buffer[1024];
|
||||
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)",
|
||||
nexus.patches->ram_size * nexus.chunk_size/(float)(1<<20),
|
||||
nexus.patches->ram_used * nexus.chunk_size/(float)(1<<20));
|
||||
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_used * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.09, buffer);
|
||||
|
||||
sprintf(buffer, "Vbo size : %.3fMb(max) %.3fMb(cur)",
|
||||
nexus.patches.vbo_max * nexus.chunk_size/(float)(1<<20),
|
||||
sprintf(buffer, "Vbo size : %.3fMb(cur)",
|
||||
nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.06, buffer);
|
||||
|
||||
|
@ -458,7 +467,7 @@ int main(int argc, char *argv[]) {
|
|||
"%.3f time %.2f FPS",
|
||||
nexus.tri_total/(float)(1<<10),
|
||||
nexus.tri_rendered/(float)(1<<10),
|
||||
tframe, 1/tframe);
|
||||
ftime, 1/ftime);
|
||||
gl_print(0.03, 0.03, buffer);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
@ -469,7 +478,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
tframe = watch.Time();
|
||||
tframe[offset++%5] = watch.Time();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,11 +31,17 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
|
|||
notloaded++;
|
||||
} else {
|
||||
PatchInfo &info = mt->index[patch];
|
||||
QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, 0.0f, flush);
|
||||
if(flush.size() != 0) {
|
||||
//WORKING QueuePServer::Data &data = mt->patches.Lookup(patch, info.nvert, info.nface, 0.0f, flush);
|
||||
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";
|
||||
exit(0);
|
||||
}
|
||||
} */
|
||||
mt->todraw.push_back(&data);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
|
||||
QueuePServer &ps = mt->patches;
|
||||
/* WORKING QueuePServer &ps = mt->patches;
|
||||
for(unsigned int i = 0; i < ps.heap.size(); i++) {
|
||||
PServer::Item &item = ps.heap[i];
|
||||
if(tmp.count(item.patch))
|
||||
|
@ -61,14 +67,9 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
|
|||
if(item.priority == 0)
|
||||
item.priority = 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'!
|
||||
reverse(missing.begin(), missing.end());
|
||||
|
@ -77,19 +78,25 @@ void Prefetch::init(NexusMt *m, std::vector<unsigned int> &selected,
|
|||
safety.unlock();
|
||||
}
|
||||
|
||||
void Prefetch::execute() {
|
||||
void Prefetch::execute() {
|
||||
unsigned int prefetched = 0;
|
||||
while(1) {
|
||||
if(get_signaled()) return;
|
||||
vector<QueuePServer::Data> flush;
|
||||
|
||||
if(load.get_count() || missing.size() == 0) {
|
||||
if(prefetched)
|
||||
cerr << "Prefetched: " << prefetched << endl;
|
||||
prefetched = 0;
|
||||
|
||||
pt::message *msg = load.getmessage();
|
||||
if(msg->id != 0xffffffff) {
|
||||
safety.lock();
|
||||
PatchInfo &info = mt->index[msg->id];
|
||||
|
||||
//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);
|
||||
msg->result = msg->id;
|
||||
draw.post(msg);
|
||||
|
@ -109,19 +116,23 @@ void Prefetch::execute() {
|
|||
PServer::Item item = missing.back();
|
||||
missing.pop_back();
|
||||
|
||||
if(item.priority > mt->patches.MaxPriority()) {
|
||||
/*Working if(item.priority > mt->patches.MaxPriority()) {
|
||||
missing.clear();
|
||||
|
||||
} else {
|
||||
} else { */
|
||||
PatchInfo &info = mt->index[item.patch];
|
||||
//cerr << "prefetching: " << item.patch << endl;
|
||||
mt->patches.Lookup(item.patch, info.nvert, info.nface, item.priority, 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 mt->patches.Lookup(item.patch, info.nvert, info.nface, item.priority, flush);
|
||||
if(!mt->patches.entries[item.patch].patch) {
|
||||
mt->patches.Lookup(item.patch, info.nvert, info.nface, flush);
|
||||
prefetched++;
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ void PServer::AddPatch(unsigned short nvert, unsigned short nface) {
|
|||
entry.patch_start = 0xffffffff;
|
||||
entry.ram_size = Patch::ChunkSize(signature, nvert, nface, chunk_size);
|
||||
entry.disk_size = 0xffff;
|
||||
entry.patch = NULL;
|
||||
entries.push_back(entry);
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ Patch *PServer::LoadPatch(unsigned int idx,
|
|||
if(entry.patch) return entry.patch;
|
||||
|
||||
char *ram = new char[entry.ram_size * chunk_size];
|
||||
#ifdef CONTROLS
|
||||
#ifndef NDEBUG
|
||||
if(!ram) {
|
||||
cerr << "COuld not allocate ram!\n";
|
||||
exit(0);
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace std;
|
|||
using namespace nxs;
|
||||
using namespace pt;
|
||||
|
||||
|
||||
/*
|
||||
QueuePServer::Data &QueuePServer::Lookup(unsigned int patch,
|
||||
unsigned short nv, unsigned short nf,
|
||||
float priority,
|
||||
|
@ -33,85 +33,12 @@ QueuePServer::Data &QueuePServer::Lookup(unsigned int 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,
|
||||
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) {
|
||||
return index.count(patch);
|
||||
|
@ -128,10 +55,10 @@ void QueuePServer::Flush() {
|
|||
FlushVbo((*i).second);
|
||||
FlushPatch((*i).first, (*i).second.patch);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
void QueuePServer::LoadVbo(Data &data) {
|
||||
if(!vbo_max) return;
|
||||
//WORKING if(!vbo_max) return;
|
||||
Patch &patch = *data.patch;
|
||||
glGenBuffersARB(1, &data.vbo_element);
|
||||
assert(data.vbo_element);
|
||||
|
@ -157,7 +84,7 @@ void QueuePServer::LoadVbo(Data &data) {
|
|||
vbo_used += size;
|
||||
}
|
||||
void QueuePServer::FlushVbo(Data &data) {
|
||||
if(!vbo_max) return;
|
||||
//WORKING if(!vbo_max) return;
|
||||
if(!data.vbo_element) return;
|
||||
//glDeleteBuffersARB(1, &data.vbo_element);
|
||||
//glDeleteBuffersARB(1, &data.vbo_array);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace nxs {
|
||||
|
||||
|
||||
class QueuePServer: public PServer {
|
||||
public:
|
||||
|
||||
|
@ -23,27 +24,72 @@ class QueuePServer: public PServer {
|
|||
Data(): patch(NULL), vbo_array(0), vbo_element(0) {}
|
||||
};
|
||||
|
||||
pt::jobqueue queue;
|
||||
|
||||
pt::jobqueue queue;
|
||||
unsigned int vbo_used;
|
||||
unsigned int vbo_max;
|
||||
|
||||
std::map<unsigned int, Data> index;
|
||||
std::vector<Item> heap;
|
||||
|
||||
QueuePServer(): queue(64000) {}
|
||||
typedef std::pair<unsigned int, Data> Item;
|
||||
std::list<Item> items;
|
||||
typedef std::list<Item> Items;
|
||||
std::map<unsigned int, Items::iterator> index;
|
||||
|
||||
//Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf,
|
||||
// float priority = 0.0f);
|
||||
QueuePServer(): queue(64000), vbo_used(0) {}
|
||||
~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.
|
||||
Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, float priority,
|
||||
std::vector<QueuePServer::Data> &data);
|
||||
|
||||
bool IsLoaded(unsigned int patch);
|
||||
float MaxPriority();
|
||||
void Flush();
|
||||
//Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, float priority,
|
||||
// std::vector<QueuePServer::Data> &data);
|
||||
|
||||
//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 FlushVbo(Data &data);
|
||||
};
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Support for mfile (>4Gb)
|
||||
|
||||
|
@ -61,19 +64,19 @@ void Watch::Start(void) {
|
|||
elapsed = 0;
|
||||
}
|
||||
|
||||
float Watch::Pause() {
|
||||
double Watch::Pause() {
|
||||
QueryPerformanceCounter(&tend);
|
||||
elapsed += Diff();
|
||||
return (float)elapsed;
|
||||
return (double)elapsed;
|
||||
}
|
||||
|
||||
void Watch::Continue() {
|
||||
QueryPerformanceCounter(&tstart);
|
||||
}
|
||||
|
||||
float Watch::Time() {
|
||||
double Watch::Time() {
|
||||
QueryPerformanceCounter(&tend);
|
||||
return (float)(elapsed + Diff());
|
||||
return (double)(elapsed + Diff());
|
||||
}
|
||||
|
||||
double Watch::Diff() {
|
||||
|
@ -91,19 +94,19 @@ void Watch::Start() {
|
|||
elapsed = 0;
|
||||
}
|
||||
|
||||
float Watch::Pause() {
|
||||
double Watch::Pause() {
|
||||
gettimeofday(&tend, &tz);
|
||||
elapsed += Diff();
|
||||
return (float)elapsed;
|
||||
return (double)elapsed;
|
||||
}
|
||||
|
||||
void Watch::Continue() {
|
||||
gettimeofday(&tstart, &tz);
|
||||
}
|
||||
|
||||
float Watch::Time() {
|
||||
double Watch::Time() {
|
||||
gettimeofday(&tend, &tz);
|
||||
return (float)(elapsed + Diff());
|
||||
return (double)(elapsed + Diff());
|
||||
}
|
||||
|
||||
double Watch::Diff() {
|
||||
|
@ -127,7 +130,7 @@ int Watch::Usec() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Report::Init(unsigned int t, float inter) {
|
||||
void Report::Init(unsigned int t, double inter) {
|
||||
watch.Start();
|
||||
tot = t;
|
||||
last = 0;
|
||||
|
@ -136,17 +139,17 @@ void Report::Init(unsigned int t, float inter) {
|
|||
|
||||
void Report::Step(unsigned int count) {
|
||||
if(count == 0) return;
|
||||
float now = watch.Time();
|
||||
double now = watch.Time();
|
||||
if(now - last < interval) return;
|
||||
//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",
|
||||
count, tot, now, tot_time - now, tot_time);
|
||||
last = now;
|
||||
}
|
||||
|
||||
void Report::Finish() {
|
||||
float now = watch.Time();
|
||||
double now = watch.Time();
|
||||
printf("Tot: %.1f\tN: %d\tN/sec: %.1f\n",
|
||||
now, tot, tot/now);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
winsockapi include problem
|
||||
|
||||
|
@ -65,10 +68,10 @@ class Watch {
|
|||
public:
|
||||
Watch();
|
||||
void Start();
|
||||
float Pause();
|
||||
double Pause();
|
||||
void Continue();
|
||||
void Reset();
|
||||
float Time();
|
||||
double Time();
|
||||
int Usec();
|
||||
private:
|
||||
double Diff();
|
||||
|
@ -85,13 +88,13 @@ private:
|
|||
|
||||
class Report {
|
||||
public:
|
||||
Report(unsigned int tot = 1, float inter = 30.0f) { Init(tot, inter); }
|
||||
void Init(unsigned int tot, float inter = 30.0f);
|
||||
Report(unsigned int tot = 1, double inter = 30.0f) { Init(tot, inter); }
|
||||
void Init(unsigned int tot, double inter = 30.0f);
|
||||
void Step(unsigned int count);
|
||||
void Finish();
|
||||
private:
|
||||
Watch watch;
|
||||
int tot;
|
||||
float last;
|
||||
float interval;
|
||||
double last;
|
||||
double interval;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue