23,6 → 23,8 |
public static void main(String[] args) |
throws Exception |
{ |
Sweeper.init(); |
|
DiskBench db = new DiskBench(); |
|
if(db.parseParams(args)) |
459,6 → 461,7 |
|
// sequential write |
if(createFile) { |
Sweeper.addFile(fileName); |
result.sequentialWriteStart = System.currentTimeMillis(); |
for(int j = 0; j < length / bufLength; j++) { |
file.write(buf); |
529,6 → 532,7 |
catch(Exception ex) { |
log.warn(Integer.toString(id) + ": cannot delete the test file", ex); |
} |
Sweeper.removeFile(fileName); |
} |
} |
|
536,6 → 540,59 |
} |
} |
|
class Sweeper |
{ |
private static Log log = LogFactory.getLog(Sweeper.class); |
private static ArrayList files = new ArrayList(); |
|
public static void addFile(String fileName) |
{ |
synchronized(files) |
{ |
log.debug("Add file '" + fileName + "'"); |
files.add(fileName); |
} |
} |
|
public static void removeFile(String fileName) |
{ |
synchronized(files) |
{ |
log.debug("Remove file '" + fileName + "'"); |
files.remove(fileName); |
} |
} |
|
public static void init() |
{ |
log.debug("Init"); |
Runtime.getRuntime().addShutdownHook(new ShutdownThread()); |
} |
|
static class ShutdownThread extends Thread |
{ |
public void run() |
{ |
log.debug("Cleanup"); |
|
synchronized(files) |
{ |
for(int i = 0; i < files.size(); i++) { |
String fileName = (String)files.get(i); |
|
try { |
(new File(fileName)).delete(); |
log.info("Test file '" + fileName + "' deleted"); |
} |
catch(Exception ex) { |
log.warn("cannot delete test file '" + fileName + "'", ex); |
} |
} |
} |
} |
} |
} |
|
class Utils |
{ |
private static final String[] units = {"", "K", "M", "G", "T", "P"}; |