Exemplo n.º 1
0
zidcu::Transaction::~Transaction() {
	_end.executeVoid();

	static Clock clock{};
	static auto checkpointTS = clock.now();

	if(clock.now() > checkpointTS + 600) {
		cerr << checkpointTS << " checkpointing... " << endl;
		checkpointTS = clock.now();
		sqlite3_wal_checkpoint(_db.getDB(), nullptr);
		cerr << clock.now() << "     done" << endl;
	}
}
Exemplo n.º 2
0
void tsk3(VP_INT exinf)
{
	while(1)
	{
		lcd.cursor(0, 4);
		lcd.putf("sd", "Task3: ", clock.now(),8);

		clock.sleep(2999); // sleep over 2999 msec
	}
}
Exemplo n.º 3
0
void tsk2(VP_INT exinf)
{
	while(1)
	{
		lcd.cursor(0, 3);
		lcd.putf("sd", "Task2: ", clock.now(),8);

		clock.sleep(1999); // sleep over 1999 msec
	}
}
Exemplo n.º 4
0
void tsk1(VP_INT exinf)
{
	while(1)
	{
		lcd.cursor(0, 2);
		lcd.putf("sd", "Task1: ", clock.now(),8);
		lcd.disp();

		clock.sleep(999); // sleep over 999 msec
	}
}
Exemplo n.º 5
0
//The protocol/transport stack test driver
//
// Reads two command line arguments
// Arg1 chooses the transport, memory or file (m|f)
// Arg2 chooses the protocol, binary/compact/json (b|c|j)
// example: 
//     proto_write_times f j
// to run the test with a file transport and JSON protocol
int main(int argc, char *argv[]) {
    if (argc != 3) {					
        std::cout << "usage: " << argv[0] 
                  << " (m[emory]|f[file]) (b[inary]|c[ompact]|j[son])" 
         << std::endl;
        return -1;
    }

	//Set the Transport
    boost::shared_ptr<TTransport> trans;			
    if (argv[1][0] == 'm' || argv[1][0] == 'M') {
        const int mem_size = 1024*1024*64;
        trans.reset(new TMemoryBuffer(mem_size));
        std::cout << "Writing memory, buffer size: " << mem_size 
                  << std::endl;
    }
    else if (argv[1][0] == 'f' || argv[1][0] == 'F') {
        const std::string path_name("/tmp/thrift_data");
        trans.reset(new TSimpleFileTransport(path_name, false, true));
        std::cout << "Writing to: " << path_name << std::endl;
    }
    else {
        std::cout << "usage: " << argv[0] 
                  << " (m[emory]|f[file]) (b[inary]|c[ompact]|j[son])" 
                  << std::endl;
        return -1;
    }

	//Set the Protocol
    std::unique_ptr<TProtocol> proto;			
    if (argv[2][0] == 'b' || argv[2][0] == 'B')
        proto.reset(new TBinaryProtocol(trans));
    else if (argv[2][0] == 'c' || argv[2][0] == 'C')
        proto.reset(new TCompactProtocol(trans));
    else if (argv[2][0] == 'j' || argv[2][0] == 'J')
        proto.reset(new TJSONProtocol(trans));
    else {
        std::cout << "usage: " << argv[0] << 
 			" (m[emory]|f[file]) (b[inary]|c[ompact]|j[son])" 
                  << std::endl;
        return -1;
    }

	//Report clock information
    Clock<std::chrono::steady_clock> clock;
    std::cout << "Clock precision in seconds: " << clock.precision() 	
 		  << " (steady: " << clock.isSteady() << ")" << std::endl;

	//Init the object (different values can have an affect on 
	//JSON ad Compact protocol performance !)
    Trade trade;
    trade.symbol[0] = 'F'; trade.symbol[1] = '\0';
    trade.price = 13.10;
    trade.size = 2500;

	//Serialize the object and write to the transport 1mm times
    auto start = clock.now();
    int i = 0;
    for (int loop_count = 0; loop_count < 1000000; ++loop_count) { 
        i += proto->writeStructBegin("Trade");

        i += proto->writeFieldBegin("symbol", 
                                    ::apache::thrift::protocol::T_STRING, 
                                    1);
        i += proto->writeString(std::string(trade.symbol));
        i += proto->writeFieldEnd();

        i += proto->writeFieldBegin("price", 
                                    ::apache::thrift::protocol::T_DOUBLE, 
                                    2);
        i += proto->writeDouble(trade.price);
        i += proto->writeFieldEnd();

        i += proto->writeFieldBegin("size", 
                                    ::apache::thrift::protocol::T_I32, 3);
        i += proto->writeI32(trade.size);
        i += proto->writeFieldEnd();

        i += proto->writeFieldStop();
        i += proto->writeStructEnd();
    }

	//Report the results
    std::cout << "elapsed: " << clock.elapsed(start, clock.now()) 
              << std::endl;
    std::cout << "Wrote " << i << " bytes" << std::endl;
}
Exemplo n.º 6
0
double Time::now() {
    Clock *clk = getClock();
    if (clk) return clk->now();
    return SystemClock::nowSystem();
}
Exemplo n.º 7
0
 Clock::Clock(const Clock &obj) :
     m_theTime(obj.now()) {}