示例#1
0
文件: ptstimer.hpp 项目: grokus/exp
    uint64_t usecs()
    {
        if (!stopped)
            split();

        return (usecs(t2) - usecs(t1));
    }
示例#2
0
void Timeval::operator+=(const DelayInterval& arg2) {
  secs() += arg2.seconds(); usecs() += arg2.useconds();
  if (useconds() >= MILLION) {
    usecs() -= MILLION;
    ++secs();
  }
}
示例#3
0
void Timeval::operator-=(const DelayInterval& arg2) {
  secs() -= arg2.seconds(); usecs() -= arg2.useconds();
  if (usecs() < 0) {
    usecs() += MILLION;
    --secs();
  }
  if (secs() < 0)
    secs() = usecs() = 0;
}
示例#4
0
    virtual void wrapup()
    {
        size_t size = boost::num_vertices(graph);
        info(
            "done, %.2f secs, found %" PRIu64 " address(es) \n",
            1e-6*(usecs() - startTime),
            size
        );

        info("Clustering ... ");
        startTime = usecs();

        std::vector<uint64_t> cc(size);
        uint64_t nbCC = boost::connected_components(graph, &cc[0]);
        info(
            "done, %.2f secs, found %" PRIu64 " clusters.\n",
            1e-6*(usecs() - startTime),
            nbCC
        );

        auto e = rootHashes.end();
        auto i = rootHashes.begin();
        while(e!=i) {

            uint64_t count = 0;
            const uint8_t *keyHash = (i++)->v;

            uint8_t b58[128];
            hash160ToAddr(b58, keyHash);
            info("Address cluster for address %s:", b58);

            auto j = addrMap.find(keyHash);
            if(unlikely(addrMap.end()==j)) {
                warning("specified key was never used to spend coins");
                showFullAddr(keyHash);
                printf("\n");
                count = 1;
            } else {
                uint64_t addrIndex = j->second;
                uint64_t homeComponentIndex = cc[addrIndex];
                for(size_t k=0; likely(k<cc.size()); ++k) {
                    uint64_t componentIndex = cc[k];
                    if(unlikely(homeComponentIndex==componentIndex)) {
                        Addr *addr = allAddrs[k];
                        showFullAddr(addr->v);
                        printf("\n");
                        ++count;
                    }
                }
            }
            info("%" PRIu64 " addresse(s)\n", count);
        }
    }
示例#5
0
    virtual int init(
        int argc,
        const char *argv[]
    )
    {
        optparse::Values &values = parser.parse_args(argc, argv);

        auto args = parser.args();
        for(size_t i=1; i<args.size(); ++i) {
            loadKeyList(rootHashes, args[i].c_str());
        }

        if(0==rootHashes.size()) {
            const char *addr = getInterestingAddr();
            loadKeyList(rootHashes, addr);
        }

        addrMap.setEmptyKey(gEmptyKey);
        addrMap.resize(15 * 1000 * 1000);
        allAddrs.reserve(15 * 1000 * 1000);
        info("Building address equivalence graph ...");
        startTime = usecs();

        return 0;
    }
示例#6
0
    virtual int init(
        int argc,
        const char *argv[]
    )
    {
        optparse::Values &values = parser.parse_args(argc, argv);

        auto args = parser.args();
        for(size_t i=1; i<args.size(); ++i) {
            loadKeyList(rootHashes, args[i].c_str());
        }

        if(0==rootHashes.size()) {
            const char *addr = "1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp";
            warning("no addresses specified, using satoshi's dice address %s", addr);
            loadKeyList(rootHashes, addr);
        }

        addrMap.setEmptyKey(gEmptyKey);
        addrMap.resize(15 * 1000 * 1000);
        allAddrs.reserve(15 * 1000 * 1000);
        info("Building address equivalence graph ...");
        startTime = usecs();

        return 0;
    }
示例#7
0
/**
 * do_read - Read from fd to rxbuf
 * @serial:	Serial Test Context
 * @bytes:	amount of data to read
 */
static int do_read(struct usb_serial_test *serial, uint32_t bytes)
{
	int				transferred = 0;
	int				done = 0;
	int				ret;
	struct usbdevfs_bulktransfer	bulk;

	gettimeofday(&start, NULL);
	while (done < bytes) {
		bulk.ep = serial->eprx;
		bulk.len = bytes - done;
		if (bulk.len > MAX_USBFS_BUFFER_SIZE)
			bulk.len = MAX_USBFS_BUFFER_SIZE;
		bulk.timeout = TIMEOUT;
		bulk.data = (unsigned char *)serial->rxbuf + done;

		ret = ioctl(serial->udevh, USBDEVFS_BULK, &bulk);
		if (ret < 0) {
			DBG("%s: failed receiving %d/%d bytes\n", __func__, done, bytes);
			goto err;
		}
		transferred = ret;

		done += transferred;
	}
	gettimeofday(&end, NULL);
	serial->read_tput = throughput(usecs(&start, &end), done);
	if (done > 0)
		serial->read_usecs += usecs(&start, &end);

	/* total average over duration of test */
	serial->read_avgtput = throughput(serial->read_usecs,
					serial->transferred);

	if (serial->read_tput > serial->read_maxtput)
		serial->read_maxtput = serial->read_tput;

	if (serial->read_tput < serial->read_mintput)
		serial->read_mintput = serial->read_tput;

	return 0;

err:
	return ret;
}
示例#8
0
int main(
    int  argc,
    char *argv[]
)
{
    double start = usecs();

        initCallback(argc, argv);
        mapBlockChainFiles();
        initHashtables();
        firstPass();
        secondPass();
        cleanMaps();

    double elapsed = (usecs()-start)*1e-6;
    info("all done in %.3f seconds\n", elapsed);
    return 0;
}
示例#9
0
    virtual void startBlock(
        const Block *b,
        uint64_t chainSize
    )
    {
        curBlock = b;

        const uint8_t *p = b->data;
        const uint8_t *sz = -4 + p;
        LOAD(uint32_t, size, sz);
        offset += size;

        double now = usecs();
        static double startTime = 0;
        static double lastStatTime = 0;
        double elapsed = now - lastStatTime;
        bool longEnough = (5*1000*1000<elapsed);
        bool closeEnough = ((chainSize - offset)<80);
        if(unlikely(longEnough || closeEnough)) {

            if(0==startTime) {
                startTime = now;
            }

            double progress = offset/(double)chainSize;
            double elasedSinceStart = 1e-6*(now - startTime);
            double speed = progress / elasedSinceStart;
            info(
                "%8" PRIu64 " blocks, "
                "%8.3f MegaAddrs , "
                "%6.2f%% , "
                "elapsed = %5.2fs , "
                "eta = %5.2fs , "
                ,
                curBlock->height,
                addrMap.size()*1e-6,
                100.0*progress,
                elasedSinceStart,
                (1.0/speed) - elasedSinceStart
            );

            lastStatTime = now;
        }

        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, bTime, p);
        blockTime = bTime;

        if(0<=cutoffBlock && cutoffBlock<=curBlock->height) {
            wrapup();
        }
    }
示例#10
0
int main(int argc, char * argv[])
{
   int i;
   long t_start,t_end;
   double time;

   A = malloc((N+2) * sizeof(double *));
   for (i=0; i<N+2; i++) {
	A[i] = malloc((N+2) * sizeof(double)); 
   }

   initialize(A, N);

   t_start=usecs();
   solve(A, N);
   t_end=usecs();

   time = ((double)(t_end-t_start))/1000000;
   printf("Computation time = %f\n", time);

}
示例#11
0
int main(
    int   argc,
    char *argv[]
) {

    auto start = usecs();

    initCallback(argc, argv);
    makeBlockMaps();
    initHashtables();
    buildNullBlock();
    buildBlockHeaders();
    computeBlockHeights();
    wireLongestChain();
    parseLongestChain();
    cleanMaps();

    auto elapsed = (usecs() - start)*1e-6;
    info("all done in %.2f seconds\n", elapsed);
    return 0;
}
示例#12
0
std::string Document::generate(){
    if(getenv("EQBEATS_HTTPS"))
        addHttp("Strict-Transport-Security: max-age=15552000\n"); // six months

    if(!_redir.empty()){
        if(_moved)
            return _http + Http::moved(_redir);
        else
            return _http + Http::redirect(_redir);
    }

    else if(dw)
        return _http + Http::download(dw, _attachment);

    if(!_content.empty())
        return _http + Http::header(_mime, _code) + _content;

    std::string out;
    if(_tpl.empty())
        setHtml("html/404.tpl", "404 Not Found", 404);

    if(_mime == "text/html" && _rootDict != _dict){
        _dict->SetFilename(_tpl);
        _rootDict->SetValueAndShowSection("REDIRECT", path, "HAS_REDIRECT");
        _rootDict->SetFormattedValue("GENERATION_TIME", "%lu µS", usecs());
        _rootDict->SetFormattedValue("PID", "%d", getpid());
        cache.ExpandWithData("html/page.tpl", ctemplate::STRIP_BLANK_LINES, _rootDict, NULL, &out);
    }

    else if(_mime == "application/json" && _rootDict != _dict){
        addHttp("Access-Control-Allow-Origin: *\n");
        if(!cgi("jsonp").empty()){
            _mime = "text/javascript";
            _rootDict->SetValueAndShowSection("FUNCTION", cgi("jsonp"), "JSONP");
        }
        _dict->SetFilename(_tpl);
        cache.ExpandWithData("json/jsonp.tpl", ctemplate::STRIP_WHITESPACE, _rootDict, NULL, &out);
    }

    else
        cache.ExpandWithData(_tpl, ctemplate::STRIP_BLANK_LINES, _rootDict, NULL, &out);

    return _http + Http::header(_mime, _code) + out;
}
示例#13
0
文件: pingpong.c 项目: ananos/cci
static void do_client(void)
{
	int ret;
	uint32_t min = 0, max;
	struct timeval start, end;
	char *func;
	char *header = "Done";

	/* initiate connect */
	ret =
	    cci_connect(endpoint, server_uri, &opts, sizeof(opts), attr, NULL,
			0, NULL);
	check_return(endpoint, "cci_connect", ret, 1);

	/* poll for connect completion */
	while (!connect_done)
		poll_events();

	if (!connection) {
		fprintf(stderr, "no connection\n");
		return;
	}

	while (!ready)
		poll_events();

	if (opts.method == MSGS) {
		func = "cci_send";
		max = connection->max_send_size;
	} else {
		func = "cci_rma";
		max = opts.max_rma_size;
	}

	ret = posix_memalign((void **)&buffer, 4096, max);
	check_return(endpoint, "memalign buffer", ret, 1);

	memset(buffer, 'b', max);

	if (opts.method != MSGS) {
		int flags = 0;

		/* for the client, we want the opposite of the opts.method.
		 * when testing RMA WRITE, we only need READ access.
		 * when testing RMA READ, we need WRITE access.
		 */

		if (opts.method == RMA_WRITE)
			flags = CCI_FLAG_READ;
		else if (opts.method == RMA_READ)
			flags = CCI_FLAG_WRITE;

		ret = cci_rma_register(endpoint, buffer, max, flags,
				       &local_rma_handle);
		check_return(endpoint, "cci_rma_register", ret, 1);
		fprintf(stderr, "local_rma_handle is %p\n",
			(void*)local_rma_handle);
		min = 1;
		if (opts.method == RMA_WRITE)
			opts.flags |= CCI_FLAG_WRITE;
		else
			opts.flags |= CCI_FLAG_READ;
	}

	if (remote_completion) {
		rmt_comp_msg = header;
		rmt_comp_len = 4;
	}

	if (opts.method == MSGS)
		printf("Bytes\t\tLatency (one-way)\tThroughput\n");
	else
		printf("Bytes\t\tLatency (round-trip)\tThroughput\n");

	/* begin communication with server */
	for (current_size = min; current_size <= max;) {
		double lat = 0.0;
		double bw = 0.0;

		if (opts.method == MSGS)
			ret =
			    cci_send(connection, buffer, current_size, NULL,
				     opts.flags);
		else
			ret = cci_rma(connection, rmt_comp_msg, rmt_comp_len,
				      local_rma_handle, 0,
				      &opts.rma_handle, 0,
				      current_size, (void *)1, opts.flags);
		check_return(endpoint, func, ret, 1);

		while (count < warmup)
			poll_events();

		gettimeofday(&start, NULL);

		while (count < warmup + iters)
			poll_events();

		gettimeofday(&end, NULL);

		if (opts.method == MSGS)
			lat = usecs(start, end) / (double)iters / 2.0;
		else
			lat = usecs(start, end) / (double)iters;

		bw = (double)current_size / lat;
		printf("%8d\t%8.2f us\t\t%8.2f MB/s\n", current_size, lat,
		       bw);

		count = 0;

		if (current_size == 0)
			current_size++;
		else
			current_size *= 2;

		if (current_size >= 64 * 1024) {
			if (iters >= 32)
				iters /= 2;
			if (warmup >= 4)
				warmup /= 2;
		}
	}

	ret = cci_send(connection, "bye", 3, (void *)0xdeadbeef, opts.flags);
	check_return(endpoint, "cci_send", ret, 0);

	while (!done)
		poll_events();

	if (opts.method != MSGS) {
		ret = cci_rma_deregister(endpoint, local_rma_handle);
		check_return(endpoint, "cci_rma_deregister", ret, 1);
	}

	printf("client done\n");
	sleep(1);

	return;
}
示例#14
0
文件: ptstimer.hpp 项目: grokus/exp
 uint64_t msecs()
 {
     return usecs() / 1000;
 }
示例#15
0
int CocoaVideoDriver::ticks() const {
    return usecs() * 60 / 1000000;
}
示例#16
0
/**
 * do_write - Write txbuf to fd
 * @serial:	Serial Test Context
 * @bytes:	amount of data to write
 */
static int do_write(struct usb_serial_test *serial, uint32_t bytes)
{
	int				transferred = 0;
	int				done = 0;
	int				ret;
	struct usbdevfs_bulktransfer	bulk;

	serial->txbuf[0] = (bytes >> 24) & 0xFF;
	serial->txbuf[1] = (bytes >> 16) & 0xFF;
	serial->txbuf[2] = (bytes >>  8) & 0xFF;
	serial->txbuf[3] = (bytes >>  0) & 0xFF;
	if (bytes > 4)
		serial->txbuf[bytes-1] = 0xff;

	gettimeofday(&start, NULL);
	while (done < bytes) {
		bulk.ep = serial->eptx;
		bulk.len = bytes - done;
		if (bulk.len > MAX_USBFS_BUFFER_SIZE)
			bulk.len = MAX_USBFS_BUFFER_SIZE;
		bulk.timeout = TIMEOUT;
		bulk.data = serial->txbuf + done;

		ret = ioctl(serial->udevh, USBDEVFS_BULK, &bulk);
		if (ret < 0) {
			DBG("%s: failed to send data\n", __func__);
			goto err;
		}
		transferred = ret;

		serial->transferred += transferred;
		done += transferred;
	}
	gettimeofday(&end, NULL);
	serial->write_tput = throughput(usecs(&start, &end), done);
	if (done > 0)
		serial->write_usecs += usecs(&start, &end);

	/* total average over duration of test */
	serial->write_avgtput = throughput(serial->write_usecs,
					serial->transferred);

	if (serial->write_tput > serial->write_maxtput)
		serial->write_maxtput = serial->write_tput;

	if (serial->write_tput < serial->write_mintput)
		serial->write_mintput = serial->write_tput;

	if (!(bytes % 512)) {
		bulk.ep = serial->eptx;
		bulk.len = 0;
		bulk.timeout = TIMEOUT;
		bulk.data = serial->txbuf + done;
		ret = ioctl(serial->udevh, USBDEVFS_BULK, &bulk);
		if (ret < 0) {
			DBG("%s: failed to send data\n", __func__);
			goto err;
		}
	}

	return 0;

err:
	return ret;
}
示例#17
0
static void buildBlockHeaders() {

    info("pass 1 -- walk all blocks and build headers ...");

    size_t nbBlocks = 0;
    size_t baseOffset = 0;
    size_t earlyMissCnt = 0;
    uint8_t buf[8+gHeaderSize];
    const auto sz = sizeof(buf);
    const auto startTime = usecs();
    const auto oneMeg = 1024 * 1024;

    for(const auto &map : mapVec) {

        startMap(0);

        while(1) {

            auto nbRead = read(map.fd, buf, sz);
            if(nbRead<(signed)sz) {
                break;
            }

            startBlock((uint8_t*)0);

            uint8_t *hash = 0;
            Block *prevBlock = 0;
            size_t blockSize = 0;

            getBlockHeader(blockSize, prevBlock, hash, earlyMissCnt, buf);
            if(unlikely(0==hash)) {
                break;
            }

            auto where = lseek(map.fd, (blockSize + 8) - sz, SEEK_CUR);
            auto blockOffset = where - blockSize;
            if(where<0) {
                break;
            }

            auto block = Block::alloc();
            block->init(hash, &map, blockSize, prevBlock, blockOffset);
            gBlockMap[hash] = block;
            endBlock((uint8_t*)0);
            ++nbBlocks;
        }
        baseOffset += map.size;

        auto now = usecs();
        auto elapsed = now - startTime;
        auto bytesPerSec = baseOffset / (elapsed*1e-6);
        auto bytesLeft = gChainSize - baseOffset;
        auto secsLeft = bytesLeft / bytesPerSec;
        fprintf(
            stderr,
            "%.2f%% (%.2f/%.2f Gigs) -- %6d blocks -- %.2f Megs/sec -- ETA %.0f secs -- ELAPSED %.0f secs            \r",
            (100.0*baseOffset)/gChainSize,
            baseOffset/(1000.0*oneMeg),
            gChainSize/(1000.0*oneMeg),
            (int)nbBlocks,
            bytesPerSec*1e-6,
            secsLeft,
            elapsed*1e-6
        );
        fflush(stderr);

        endMap(0);
    }

    if(0==nbBlocks) {
        warning("found no blocks - giving up");
        exit(1);
    }

    char msg[128];
    msg[0] = 0;
    if(0<earlyMissCnt) {
        sprintf(msg, ", %d early link misses", (int)earlyMissCnt);
    }

    auto elapsed = 1e-6*(usecs() - startTime);
    info(
        "pass 1 -- took %.0f secs, %6d blocks, %.2f Gigs, %.2f Megs/secs %s                                            ",
        elapsed,
        (int)nbBlocks,
        (gChainSize * 1e-9),
        (gChainSize * 1e-6) / elapsed,
        msg
    );
}
示例#18
0
// TODO: compensate for the function call/return time?
void delay_usec(uint32 delay_time_usec) {
  const uint32 start_time = usecs();
  while (usecs() - start_time < delay_time_usec) {
    // Do nothing.
  }
}
示例#19
0
文件: rpc.c 项目: CCI/cci
static void do_client(void)
{
	int ret, i = 0;
	struct timeval start, end;
	double lat = 0.0;
	double bw = 0.0;

	ret = posix_memalign((void **)&request, 4096, opts.req_size);
	check_return(endpoint, "memalign buffer", ret, 1);

	msg = (int*) request;

	ret = posix_memalign((void **)&buffer, 4096, opts.transfer_size);
	check_return(endpoint, "memalign buffer", ret, 1);

	memset(buffer, 'b', opts.transfer_size);

	ret = cci_rma_register(endpoint, buffer, opts.transfer_size,
				opts.rma_flags, &local);
	check_return(endpoint, "cci_rma_register", ret, 1);

	memcpy(&opts.rma_handle, local, sizeof(*local));

	connect_to_server();

	if (connection->max_send_size < opts.req_size)
		opts.req_size = connection->max_send_size;

	if (!suppress)
		printf("Bytes\t\tLatency (per rpc)\tThroughput (per rpc)\n");

	/* begin communication with server */
	ret = send_request(count);
	check_return(endpoint, "send first request", ret, 1);
	if (!ret) {
		count++;
		inflight++;
	}

	progress_client(opts.warmup);

	count = 0;
	completed = 0;

	gettimeofday(&start, NULL);

	for (i = 0; i < concurrent; i++) {
		ret = send_request(count);
		if (!ret) {
			count++;
			inflight++;
		}
		check_return(endpoint, "send first request", ret, 0);
	}

	progress_client(opts.iters);

	gettimeofday(&end, NULL);

	lat = usecs(start, end) / (double)opts.iters;

	bw = (double)opts.transfer_size / lat;
	printf("%8d\t%8.2f us\t\t%8.2f MB/s\n", opts.transfer_size, lat, bw);

	ret = cci_send(connection, "bye", 3, (void *)0xdeadbeef, 0);
	check_return(endpoint, "cci_send", ret, 1);

	progress_client(0);

	ret = cci_rma_deregister(endpoint, local);
	check_return(endpoint, "cci_rma_deregister", ret, 1);

	if (!suppress)
		printf("client done\n");

	return;
}
示例#20
0
int main(
    int argc,
    char *argv[]
) {

    if(3!=argc) {
        fprintf(stderr, "usage: flashtest <device> <mode>\n");
        exit(1);
    }

    auto accessMode = (argv[2] ? argv[2][0] : '?');
    auto knownMode = ('r'==accessMode || 'w'==accessMode);
    if(false==knownMode) {
        fprintf(stderr, "unknown access mode '%c'\n", accessMode);
        exit(1);
    }

    auto fd = open(
        argv[1],
        (('w'==accessMode) ? O_WRONLY : O_RDONLY),
        O_NOATIME   |
        O_DIRECT    |
        O_SYNC
    );
    if(fd<0) {
        fprintf(stderr, "cant access file '%s'\n", argv[1]);
        perror("");
        exit(1);
    }

    std::mt19937 rng(kSeed);

    uint64_t nbBytes = 0;
    uint64_t nbBlocks = 0;
    uint64_t lastReportBytes = 0;
    auto lastReportTime = usecs();
    auto startTime = lastReportTime;

    while(1) {

        auto genStart = usecs();
            auto p = buffer0;
            auto e = kBlkWordSize + p;
            while(p<e) {
                *(p++) = rng();
            }
        auto genTime = usecs() - genStart;
        auto genGBPerSecond = (kBlkByteSize * 1e-9) / (genTime * 1e-6);

        auto report = [&](
            bool fail = false
        ) {
            if(fail) {
                perror("");
            }

            auto now = usecs();
            auto elapsedSinceStart = now - startTime;
            auto elapsedSinceLast = now - lastReportTime;
            auto speedSinceStart = nbBytes / (double)elapsedSinceStart;
            auto speedSinceLast = (nbBytes-lastReportBytes) / (double)elapsedSinceLast;

            fprintf(
                stderr,
                "%s %s%s block %" PRIu64 "\n"
                "\n"
                "    %14" PRIu64 ".000  Bytes\n"
                "    %18.3f MBytes\n"
                "    %18.3f GBytes\n"
                "\n"
                "    %18.3f second elapsed since program start\n"
                "    %18.3f second elapsed since last report\n"
                "    %18.3f GB/Sec RNG generation speed\n"
                "\n"
                "    %18.3f MB/Sec (avg. since program start)\n"
                "    %18.3f MB/Sec (avg. since last report)\n"
                "\n"
                ,
                ('w'==accessMode) ? "writing to" : "reading from",
                argv[1],
                fail ? " failed" : "",
                nbBlocks,
                nbBytes,
                nbBytes * 1e-6,
                nbBytes * 1e-9,
                elapsedSinceStart * 1e-6,
                elapsedSinceLast * 1e-6,
                genGBPerSecond,
                speedSinceStart,
                speedSinceLast
            );

            lastReportBytes = nbBytes;
            lastReportTime = now;
        };

        if('w'==accessMode) {
            auto r0 = write(fd, buffer0, kBlkByteSize);
            if(0<=r0) {
                nbBytes += r0;
            }
            if(kBlkByteSize!=(unsigned)r0) {
                report(true);
                break;
            }

            auto r1 = fdatasync(fd);
            if(r1<0) {
                report(true);
                break;
            }
        } else {
            auto r = read(fd, buffer1, kBlkByteSize);
            if(0<=r) {
                nbBytes += r;
            }

            bool equal = (0==memcmp(buffer0, buffer1, r));
            if(false==equal) {
                fprintf(
                    stderr,
                    "FAIL -- found unexpected data at block %" PRIu64 " !!!!!!!!!!!!!!!!!\n\n",
                    nbBlocks
                );
                report();
                abort();
            }

            if(kBlkByteSize!=(unsigned)r) {
                report(true);
                break;
            }
        }
        ++nbBlocks;

        auto now = usecs();
        double elapsedSinceLastReport = (now - lastReportTime)*1e-6;
        if(1.0<elapsedSinceLastReport) {
            report();
        }
    }
    return 0;
}