本文整理汇总了C++中Timestamp::stamp方法的典型用法代码示例。如果您正苦于以下问题:C++ Timestamp::stamp方法的具体用法?C++ Timestamp::stamp怎么用?C++ Timestamp::stamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timestamp
的用法示例。
在下文中一共展示了Timestamp::stamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char *argv[])
{
/* parse the command line args */
if( argc < 5 )
{
cout << "Error: need 6 args! ./Driver [test file] [cache-size] [minimum chance] [lookahead window] [prefetch option]";
return 0;
}
string prefetch_arg = argv[5];
/* prefetch / yes or no */
bool prefetch_option = false;
if( prefetch_arg.compare("true") == 0 )
prefetch_option = true;
/* create our Cache_Manager */
Cache_Manager cache_manager(prefetch_option, atoi(argv[2]), atof(argv[3]), atoi(argv[4]) );
Cache_Manager *ptr = &cache_manager;
/* create our FS_Simulator */
FS_Simulator fs_sim(ptr);
/* use TraceLoader to load our simulation data */
TraceLoader test( argv[1] );
string data = test.getData();
test.parse(data); // produces a vector of SystemCalls ordered by time ( microseconds )
/* Simulate Application system calls */
Timestamp now;
now.stamp();
double long previous_time = now.time;
SystemCall* previous_call = *test.calls.begin();
vector<SystemCall*>::iterator it = test.calls.begin();
++it;
/* convert each to seconds */
long double previous_call_time = 3600*previous_call->hourTime;
previous_call_time += 60*previous_call->minuteTime;
previous_call_time += previous_call->secondTime;
previous_call_time += (double)0.000001*(previous_call->microSecondTime);
long double current_call_time = 3600*(*it)->hourTime;
current_call_time += 60*(*it)->minuteTime;
current_call_time += (*it)->secondTime;
current_call_time += (double)0.000001*((*it)->microSecondTime);
long double elapsed_goal = current_call_time - previous_call_time;
if(elapsed_goal < 0 )
elapsed_goal = 0.05; //seconds
if(elapsed_goal > 5)
elapsed_goal = 0.05; // wait one second if it is like an hour or day or minute- we dont want to wait that long
while(it != test.calls.end() )
{
now.stamp();
if((now.time - previous_time) - elapsed_goal > -0.00001) {
systemCallToString( **it );
fs_sim.sendRequest( *it );
previous_call = *it;
previous_time = now.time;
previous_call_time = 0.0;
current_call_time = 0.0;
/* convert each to seconds */
previous_call_time += 3600*previous_call->hourTime;
previous_call_time += 60*previous_call->minuteTime;
previous_call_time += previous_call->secondTime;
previous_call_time += (double)0.000001*(previous_call->microSecondTime);
it++;
current_call_time += 3600*(*it)->hourTime;
current_call_time += 60*(*it)->minuteTime;
current_call_time += (*it)->secondTime;
current_call_time += (double)0.000001*((*it)->microSecondTime);
elapsed_goal = current_call_time - previous_call_time;
if(elapsed_goal < 0 )
elapsed_goal = 0.05; //seconds
if(elapsed_goal > 0.05)
elapsed_goal = 0.05;
}
} // end while
return 0;
}
示例2: main
int main(int argc, char* argv[]) {
thread simulate, broadcast, receive, render;
Queue<State> simulateBroadcast, receiveRender;
unsigned simulateBroadcastWasFull = 0;
unsigned simulateBroadcastWasEmpty = 0;
unsigned receiveRenderWasFull = 0;
unsigned receiveRenderWasEmpty = 0;
bool waitingToStart = true, done = false;
simulate = thread([&]() {
Timestamp<> t;
// Checksum c;
State state;
state.zero();
while (waitingToStart)
usleep(1000);
while (!done) {
sprintf(state.data, "%lf | %u", t.stamp(), state.n);
// c.checksum((unsigned char*)&state, sizeof(State));
// c.print();
// printf("\n");
if (simulateBroadcast.push(state)) {
state.n++;
} else
simulateBroadcastWasFull++;
usleep(16666);
}
});
broadcast = thread([&]() {
// Stopwatch<> stopwatch;
Broadcaster broadcaster;
broadcaster.init(PACKET_SIZE, "192.168.1.255", 8888);
// broadcaster.init(PACKET_SIZE, "127.0.0.1", 8888);
Packet<PACKET_SIZE> p;
State state;
int frame = 0;
while (waitingToStart)
usleep(1000);
while (!done) {
if (simulateBroadcast.pop(state)) { // XXX while() for greed
// stopwatch.tic();
PacketMaker<State, Packet<PACKET_SIZE> > packetMaker(state, frame);
while (packetMaker.fill(p))
broadcaster.send((unsigned char*)&p);
// printf("frame %u took %f seconds to broadcast\n", frame,
// stopwatch.toc());
frame++;
} else {
simulateBroadcastWasEmpty++;
usleep(1000);
}
}
});
receive = thread([&]() {
// Stopwatch<> stopwatch;
Receiver receiver;
receiver.init(8888);
Packet<PACKET_SIZE> p;
State state;
while (waitingToStart)
usleep(1000);
while (!done) {
/*
if (p.header.frameNumber > 0)
printf("frame %u took %f seconds to receive\n",
p.header.frameNumber,
stopwatch.toc());
*/
if (!receiver.receive((unsigned char*)&p, PACKET_SIZE, 0.2f)) {
usleep(1000);
continue;
}
// wait until we're at the begining of a frame
if (p.header.partNumber != 0)
continue;
// stopwatch.tic();
PacketTaker<State, Packet<PACKET_SIZE> > packetTaker(
state, p.header.frameNumber);
packetTaker.take(p);
while (!packetTaker.isComplete()) {
if (receiver.receive((unsigned char*)&p, PACKET_SIZE, 0.2f)) {
if (!packetTaker.take(p)) {
// got a part from an unexpected frame before we finished this frame
printf("lost frame\n");
goto ABORT_FRAME;
//.........这里部分代码省略.........