⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfsperfreader_main.cc

📁 nandflash文件系统源代码
💻 CC
字号:
//---------------------------------------------------------- -*- Mode: C++ -*-// $Id: KfsPerfReader_main.cc 71 2008-07-07 15:49:14Z sriramsrao $ //// Created 2006/06/23//// Copyright 2008 Quantcast Corp.// Copyright 2006-2008 Kosmix Corp.//// This file is part of Kosmos File System (KFS).//// Licensed under the Apache License, Version 2.0// (the "License"); you may not use this file except in compliance with// the License. You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or// implied. See the License for the specific language governing// permissions and limitations under the License.//// \brief Program that reads sequentially from a file in KFS.////----------------------------------------------------------------------------#include <iostream>    #include <unistd.h>#include <string.h>#include <stdlib.h>#include <fcntl.h>#include <fstream>#include <boost/scoped_array.hpp>#include "libkfsClient/KfsClient.h"using std::cout;using std::endl;using std::ifstream;using std::string;using namespace KFS;KfsClientPtr gKfsClient;static off_t doRead(const string &kfspathname, int numMBytes, int readSizeBytes);intmain(int argc, char **argv){    char optchar;    string kfspathname = "";    char *kfsPropsFile = NULL;    int numMBytes = 1, readSizeBytes = 65536;    bool help = false;    while ((optchar = getopt(argc, argv, "f:p:m:b:")) != -1) {        switch (optchar) {            case 'f':                kfspathname = optarg;                break;            case 'b':                readSizeBytes = atoi(optarg);                break;            case 'p':                kfsPropsFile = optarg;                break;            case 'm':                numMBytes = atoi(optarg);                break;            default:                cout << "Unrecognized flag: " << optchar << endl;                help = true;                break;        }    }    if (help || (kfsPropsFile == NULL) || (kfspathname == "")) {        cout << "Usage: " << argv[0] << " -p <Kfs Client properties file> "             << " -m <# of MB to read> -b <read size in bytes> -f <Kfs file> " << endl;        exit(0);    }    cout << "Doing reads to: " << kfspathname << " # MB = " << numMBytes;    cout << " # of bytes per read: " << readSizeBytes << endl;    gKfsClient = getKfsClientFactory()->GetClient(kfsPropsFile);    if (!gKfsClient) {        cout << "kfs client failed to initialize...exiting" << endl;        exit(-1);    }    string kfsdirname, kfsfilename;    string::size_type slash = kfspathname.rfind('/');        if (slash == string::npos) {        cout << "Bad kfs path: " << kfsdirname << endl;        exit(-1);    }    kfsdirname.assign(kfspathname, 0, slash);    kfsfilename.assign(kfspathname, slash + 1, kfspathname.size());    struct timeval startTime, endTime;    double timeTaken;    off_t bytesRead;    gettimeofday(&startTime, NULL);    bytesRead = doRead(kfspathname, numMBytes, readSizeBytes);    gettimeofday(&endTime, NULL);    timeTaken = (endTime.tv_sec - startTime.tv_sec) +        (endTime.tv_usec - startTime.tv_usec) * 1e-6;    cout << "Read rate: " << (((double) bytesRead * 8.0) / timeTaken) / (1024.0 * 1024.0) << " (Mbps)" << endl;    cout << "Read rate: " << ((double) (bytesRead) / timeTaken) / (1024.0 * 1024.0) << " (MBps)" << endl;    return 0;}off_tdoRead(const string &filename, int numMBytes, int readSizeBytes){    const int mByte = 1024 * 1024;    boost::scoped_array<char> dataBuf;    int res, bytesRead = 0, nMBytes = 0, fd;    off_t nread = 0;    dataBuf.reset(new char [mByte]);    if (readSizeBytes > mByte) {        cout << "Setting read size to: " << mByte << endl;        readSizeBytes = mByte;    }    fd = gKfsClient->Open(filename.c_str(), O_RDONLY);    if (fd < 0) {        cout << "Open failed: " << endl;        exit(-1);    }    for (nMBytes = 0; nMBytes < numMBytes; nMBytes++) {        for (bytesRead = 0; bytesRead < mByte; bytesRead += readSizeBytes) {            res = gKfsClient->Read(fd, dataBuf.get(), readSizeBytes);            if (res != readSizeBytes)                return (bytesRead + nMBytes * 1024 * 1024);            nread += readSizeBytes;        }    }    cout << "read of " << nread / (1024 * 1024) << " (MB) is done" << endl;    gKfsClient->Close(fd);    return nread;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -