void testIO(unsigned nr, SocketEndpoint *ep) { IFile *ifile; IFileIO *ifileio; unsigned fsize = (unsigned)(((double)nr * (double)rs) / (1024.0 * 1024.0)); fflush(NULL); fprintf(stdout,"\n"); fflush(NULL); for(int j=0; j<2; j++) { if (j==0) fprintf(stdout, "File size: %d (MB) Cache, ", fsize); else fprintf(stdout, "\nFile size: %d (MB) Nocache, ", fsize); if (ep != NULL) { ifile = createRemoteFile(*ep, tmpfile); fprintf(stdout, "Remote: (%s)\n", server.toCharArray()); } else { ifile = createIFile(tmpfile); fprintf(stdout, "Local:\n"); } ifile->remove(); unsigned st = msTick(); IFEflags extraFlags = IFEcache; if (j==1) extraFlags = IFEnocache; ifileio = ifile->open(IFOcreate, extraFlags); unsigned iter = nr / 40; __int64 pos = 0; for (int i=0;i<nr;i++) { ifileio->write(pos, rs, record); pos += rs; if ((i % iter) == 0) { fprintf(stdout,"."); fflush(NULL); } } ifileio->close(); double rsec = (double)(msTick() - st)/1000.0; unsigned iorate = (unsigned)((double)fsize / rsec); fprintf(stdout, "\nwrite - elapsed time = %6.2f (s) iorate = %4d (MB/s)\n", rsec, iorate); st = msTick(); extraFlags = IFEcache; if (j==1) extraFlags = IFEnocache; ifileio = ifile->open(IFOread, extraFlags); pos = 0; for (int i=0;i<nr;i++) { ifileio->read(pos, rs, record); pos += rs; if ((i % iter) == 0) { fprintf(stdout,"."); fflush(NULL); } } ifileio->close(); rsec = (double)(msTick() - st)/1000.0; iorate = (unsigned)((double)fsize / rsec); fprintf(stdout, "\nread -- elapsed time = %6.2f (s) iorate = %4d (MB/s)\n", rsec, iorate); ifileio->Release(); ifile->remove(); ifile->Release(); } }
void copyCompress(const char *from, const char *to, size32_t rowsize, bool fast, bool flzstrm, bool stats) { Owned<IFile> srcfile = createIFile(from); Owned<IFileIO> baseio = srcfile->open(IFOread); if (!baseio) { printf("ERROR: could not open '%s' for read\n",from); doexit(3); } Owned<ICompressedFileIO> cmpio = createCompressedFileReader(baseio); Owned<IFileIOStream> flzstrmsrc = cmpio?NULL:createFastLZStreamRead(baseio); bool plaincopy = false; IFileIO *srcio = NULL; if (cmpio) { srcio = cmpio; if (rowsize&&(cmpio->recordSize()==rowsize)) plaincopy = true; else if (!rowsize) { if (fast&&(cmpio->method()==COMPRESS_METHOD_FASTLZ)) plaincopy = true; else if (!fast&&(cmpio->method()==COMPRESS_METHOD_LZW)) plaincopy = true; } } else if (flzstrmsrc) { if (flzstrm) plaincopy = true; } else srcio = baseio; if (plaincopy) { cmpio.clear(); srcio = baseio.get(); } Owned<IFile> dstfile = createIFile(to); StringBuffer fulldst; if (dstfile->isDirectory()==foundYes) { dstfile.clear(); addPathSepChar(fulldst.append(to)).append(pathTail(from)); to = fulldst.str(); dstfile.setown(createIFile(to)); } if (dstfile->exists()) { printf("ERROR: file '%s' already exists\n",to); doexit(4); } unsigned start; unsigned startu; if (stats) { start = msTick(); startu = usTick(); } Owned<IFileIO> dstio; Owned<IFileIOStream> flzstrmdst; if (plaincopy||flzstrm) { dstio.setown(dstfile->open(IFOcreate)); if (dstio&&!plaincopy) flzstrmdst.setown(createFastLZStreamWrite(dstio)); } else dstio.setown(createCompressedFileWriter(dstfile,rowsize,false,true,NULL,fast)); if (!dstio) { printf("ERROR: could not open '%s' for write\n",to); doexit(5); } #ifdef __linux__ // this is not really needed in windows - if it is we will have to // test the file extension - .exe, .bat struct stat info; if (stat(from, &info) == 0) // cannot fail - exception would have been thrown above dstfile->setCreateFlags(info.st_mode&(S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH|S_IXUSR|S_IXGRP|S_IXOTH)); #endif MemoryAttr mb; void * buffer = mb.allocate(BUFFERSIZE); offset_t offset = 0; try { loop { size32_t got = cmpio.get()?cmpio->read(offset, BUFFERSIZE, buffer):srcio->read(offset, BUFFERSIZE, buffer); if (got == 0) break; if (flzstrmdst) flzstrmdst->write(got,buffer); else dstio->write(offset, got, buffer); offset += got; } } catch (IException *e) { // try to delete partial copy dstio.clear(); try { dstfile->remove(); } catch (IException *e2) { StringBuffer s; pexception(s.clear().append("Removing partial copy file: ").append(to).str(),e2); e2->Release(); } throw e; } flzstrmdst.clear(); dstio.clear(); if (stats) printStats(offset,start,startu); CDateTime createTime, modifiedTime; if (srcfile->getTime(&createTime, &modifiedTime, NULL)) dstfile->setTime(&createTime, &modifiedTime, NULL); printf("copied %s to %s%s\n",from,to,plaincopy?"":" compressing"); { // print details dstio.setown(dstfile->open(IFOread)); if (dstio) { Owned<ICompressedFileIO> cmpio = createCompressedFileReader(dstio); Owned<IFileIOStream> flzstrm = cmpio?NULL:createFastLZStreamRead(dstio); if (cmpio||flzstrm) printCompDetails(to,dstio,cmpio,flzstrm); else printf("destination %s not compressed\n",to); } else printf("destination %s could not be read\n",to); } }