jpayne@68: package fun; jpayne@68: jpayne@68: import java.io.File; jpayne@68: import java.io.IOException; jpayne@68: import java.io.InputStream; jpayne@68: import java.io.PrintStream; jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.Arrays; jpayne@68: import java.util.Locale; jpayne@68: import java.util.Random; jpayne@68: jpayne@68: import fileIO.ByteFile; jpayne@68: import fileIO.ByteStreamWriter; jpayne@68: import fileIO.FileFormat; jpayne@68: import fileIO.QuickFile; jpayne@68: import fileIO.ReadWrite; jpayne@68: import fileIO.TextFile; jpayne@68: import shared.Parse; jpayne@68: import shared.Parser; jpayne@68: import shared.PreParser; jpayne@68: import shared.Shared; jpayne@68: import shared.Timer; jpayne@68: import shared.Tools; jpayne@68: import stream.FastaReadInputStream; jpayne@68: import structures.ByteBuilder; jpayne@68: jpayne@68: /** jpayne@68: * @author Brian Bushnell jpayne@68: * @date December 6, 2017 jpayne@68: * jpayne@68: */ jpayne@68: public class DiskBench { jpayne@68: jpayne@68: public static void main(String[] args){ jpayne@68: //Start a timer immediately upon code entrance. jpayne@68: Timer t=new Timer(); jpayne@68: jpayne@68: //Create an instance of this class jpayne@68: DiskBench x=new DiskBench(args); jpayne@68: jpayne@68: //Run the object jpayne@68: x.process(t); jpayne@68: jpayne@68: //Close the print stream if it was redirected jpayne@68: Shared.closeStream(x.outstream); jpayne@68: } jpayne@68: jpayne@68: public DiskBench(String[] args){ jpayne@68: jpayne@68: {//Preparse block for help, config files, and outstream jpayne@68: PreParser pp=new PreParser(args, getClass(), false); jpayne@68: args=pp.args; jpayne@68: outstream=pp.outstream; jpayne@68: } jpayne@68: jpayne@68: ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; jpayne@68: ReadWrite.MAX_ZIP_THREADS=Shared.threads(); jpayne@68: jpayne@68: Parser parser=new Parser(); jpayne@68: parser.overwrite=true; jpayne@68: for(int i=0; i1 ? split[1] : null; jpayne@68: jpayne@68: if(a.equals("path")){ jpayne@68: path=b; jpayne@68: if(path==null){path="";} jpayne@68: else if(!path.endsWith("/")){path=path+"/";} jpayne@68: }else if(a.equals("lines")){ jpayne@68: maxLines=Long.parseLong(b); jpayne@68: if(maxLines<0){maxLines=Long.MAX_VALUE;} jpayne@68: }else if(a.equals("data") || a.equals("size")){ jpayne@68: data=Parse.parseKMG(b); jpayne@68: }else if(a.equals("passes")){ jpayne@68: passes=Integer.parseInt(b); jpayne@68: }else if(a.equals("verbose")){ jpayne@68: verbose=Parse.parseBoolean(b); jpayne@68: }else if(a.equals("gzip")){ jpayne@68: verbose=Parse.parseBoolean(b); jpayne@68: }else if(a.equals("mode")){ jpayne@68: assert(b!=null) : "Bad parameter: "+arg; jpayne@68: if(Tools.isDigit(b.charAt(0))){mode=Integer.parseInt(b);} jpayne@68: else if("read".equalsIgnoreCase(b) || "r".equalsIgnoreCase(b)){mode=READ;} jpayne@68: else if("write".equalsIgnoreCase(b) || "w".equalsIgnoreCase(b)){mode=WRITE;} jpayne@68: else if("readwrite".equalsIgnoreCase(b) || "rw".equalsIgnoreCase(b)){mode=READWRITE;} jpayne@68: else{assert(false) : "Bad mode: "+arg;} jpayne@68: }else if(a.equals("read") || a.equals("r")){ jpayne@68: mode=READ; jpayne@68: }else if(a.equals("write") || a.equals("w")){ jpayne@68: mode=WRITE; jpayne@68: }else if(a.equals("readwrite") || a.equals("rw")){ jpayne@68: mode=READWRITE; jpayne@68: }else if(a.equals("printtid")){ jpayne@68: printTid=Parse.parseBoolean(b); jpayne@68: }else if(a.equals("processbis")){ jpayne@68: processBis=Parse.parseBoolean(b); jpayne@68: }else if(a.equals("preread")){ jpayne@68: preRead=Parse.parseBoolean(b); jpayne@68: } jpayne@68: jpayne@68: else if(a.equals("method")){ jpayne@68: assert(b!=null) : "Bad parameter: "+arg; jpayne@68: if(Tools.isDigit(b.charAt(0))){method=Integer.parseInt(b);} jpayne@68: else if("BYTEFILE".equalsIgnoreCase(b) || "bf".equalsIgnoreCase(b)){method=BYTEFILE;} jpayne@68: else if("TEXTFILE".equalsIgnoreCase(b) || "tf".equalsIgnoreCase(b)){method=TEXTFILE;} jpayne@68: else if("QUICKFILE".equalsIgnoreCase(b) || "qf".equalsIgnoreCase(b)){method=QUICKFILE;} jpayne@68: else if("BUFFEREDINPUTSTREAM".equalsIgnoreCase(b) || "bis".equalsIgnoreCase(b)){method=BUFFEREDINPUTSTREAM;} jpayne@68: else if("FILEINPUTSTREAM".equalsIgnoreCase(b) || "fis".equalsIgnoreCase(b)){method=FILEINPUTSTREAM;} jpayne@68: else if("BUFFEREDINPUTSTREAM2".equalsIgnoreCase(b) || "bis2".equalsIgnoreCase(b)){method=BUFFEREDINPUTSTREAM2;} jpayne@68: else if("FILEINPUTSTREAM2".equalsIgnoreCase(b) || "fis2".equalsIgnoreCase(b)){method=FILEINPUTSTREAM2;} jpayne@68: else{assert(false) : "Bad mode: "+arg;} jpayne@68: } jpayne@68: else if("BYTEFILE".equalsIgnoreCase(a) || "bf".equalsIgnoreCase(a)){method=BYTEFILE;} jpayne@68: else if("TEXTFILE".equalsIgnoreCase(a) || "tf".equalsIgnoreCase(a)){method=TEXTFILE;} jpayne@68: else if("QUICKFILE".equalsIgnoreCase(a) || "qf".equalsIgnoreCase(a)){method=QUICKFILE;} jpayne@68: else if("BUFFEREDINPUTSTREAM".equalsIgnoreCase(a) || "bis".equalsIgnoreCase(a)){method=BUFFEREDINPUTSTREAM;} jpayne@68: else if("FILEINPUTSTREAM".equalsIgnoreCase(a) || "fis".equalsIgnoreCase(a)){method=FILEINPUTSTREAM;} jpayne@68: else if("BUFFEREDINPUTSTREAM2".equalsIgnoreCase(a) || "bis2".equalsIgnoreCase(a)){method=BUFFEREDINPUTSTREAM2;} jpayne@68: else if("FILEINPUTSTREAM2".equalsIgnoreCase(a) || "fis2".equalsIgnoreCase(a)){method=FILEINPUTSTREAM2;} jpayne@68: else if("buffer".equalsIgnoreCase(a) || "bufferlen".equalsIgnoreCase(a)){ jpayne@68: bufferlen=(int)Parse.parseKMGBinary(b); jpayne@68: } jpayne@68: jpayne@68: else if(parser.parse(arg, a, b)){ jpayne@68: //do nothing jpayne@68: }else{ jpayne@68: outstream.println("Unknown parameter "+args[i]); jpayne@68: assert(false) : "Unknown parameter "+args[i]; jpayne@68: // throw new RuntimeException("Unknown parameter "+args[i]); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: {//Process parser fields jpayne@68: overwrite=parser.overwrite; jpayne@68: threads=Shared.threads(); jpayne@68: } jpayne@68: jpayne@68: assert(FastaReadInputStream.settingsOK()); jpayne@68: jpayne@68: if(!ByteFile.FORCE_MODE_BF2){ jpayne@68: ByteFile.FORCE_MODE_BF2=false; jpayne@68: ByteFile.FORCE_MODE_BF1=true; jpayne@68: } jpayne@68: jpayne@68: File pfile=new File(path); jpayne@68: if(!pfile.exists()){pfile.mkdirs();} jpayne@68: } jpayne@68: jpayne@68: class WriteThread extends Thread{ jpayne@68: jpayne@68: public WriteThread(String fname_, long size_){ jpayne@68: fname=fname_; jpayne@68: size=size_; jpayne@68: } jpayne@68: jpayne@68: @Override jpayne@68: public void run(){ jpayne@68: t=new Timer(); jpayne@68: written=writeRandomData(fname, size, t, overwrite); jpayne@68: } jpayne@68: jpayne@68: String fname; jpayne@68: long size; jpayne@68: long written=0; jpayne@68: Timer t; jpayne@68: jpayne@68: } jpayne@68: jpayne@68: public static long writeRandomData(final String fname, final long size, final Timer t, final boolean overwrite){ jpayne@68: if(t!=null){t.start();} jpayne@68: long written=0; jpayne@68: final Random randy=Shared.threadLocalRandom(); jpayne@68: FileFormat ffout=FileFormat.testOutput(fname, FileFormat.TEXT, null, true, overwrite, false, false); jpayne@68: ByteStreamWriter bsw=new ByteStreamWriter(ffout); jpayne@68: bsw.start(); jpayne@68: final ByteBuilder bb=new ByteBuilder(66000); jpayne@68: final int shift=6; jpayne@68: final int shiftsPerRand=32/shift; jpayne@68: assert(shiftsPerRand>0); jpayne@68: final long limit=size-20-shiftsPerRand*1000; jpayne@68: while(written>=shift; jpayne@68: } jpayne@68: } jpayne@68: // for(int i=0; i<1000; i+=shiftsPerRand){ jpayne@68: // long x=randy.nextLong(); jpayne@68: // for(int j=0; j>=shift; jpayne@68: // } jpayne@68: // } jpayne@68: bb.nl(); jpayne@68: written+=bb.length; jpayne@68: bsw.print(bb); jpayne@68: bb.clear(); jpayne@68: } jpayne@68: while(written0; ){ jpayne@68: r=0; jpayne@68: try { jpayne@68: r=is.read(buffer); jpayne@68: if(r>0){read+=r;} jpayne@68: jpayne@68: if(processBis){ jpayne@68: int last=0; jpayne@68: for(int i=1; i(800); jpayne@68: for(int r=1; r>0; ){ jpayne@68: r=0; jpayne@68: try { jpayne@68: r=is.read(buffer); jpayne@68: if(r>0){read+=r;} jpayne@68: jpayne@68: if(processBis){ jpayne@68: int last=0; jpayne@68: for(int i=1; i=800){ jpayne@68: list=new ArrayList(800); jpayne@68: } jpayne@68: last=i+1; jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: } catch (IOException e) { jpayne@68: e.printStackTrace(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: try { jpayne@68: is.close(); jpayne@68: } catch (IOException e) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e.printStackTrace(); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: byte[] cache; jpayne@68: ArrayList list; jpayne@68: String fname; jpayne@68: long read=0; jpayne@68: long lines=0; jpayne@68: Timer t; jpayne@68: final int tid; jpayne@68: jpayne@68: } jpayne@68: jpayne@68: String[] makeFnames(int pass){ jpayne@68: String[] fnames=new String[threads]; jpayne@68: Random randy=new Random(); jpayne@68: for(int i=0; i