提交 ff221092 authored 作者: Ulrich Wielant's avatar Ulrich Wielant

Rename some variables to point out usage of nanoseconds time stamp

上级 f3a1598b
......@@ -54,7 +54,7 @@ public class Sentence {
*/
private String queryUpper;
private long stopAt;
private long stopAtNs;
private DbSchema lastMatchedSchema;
private DbTableOrView lastMatchedTable;
private DbTableOrView lastTable;
......@@ -65,7 +65,7 @@ public class Sentence {
* Start the timer to make sure processing doesn't take too long.
*/
public void start() {
stopAt = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(MAX_PROCESSING_TIME);
stopAtNs = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(MAX_PROCESSING_TIME);
}
/**
......@@ -74,7 +74,7 @@ public class Sentence {
* If processing is stopped, this methods throws an IllegalStateException
*/
public void stopIfRequired() {
if (System.nanoTime() > stopAt) {
if (System.nanoTime() > stopAtNs) {
throw new IllegalStateException();
}
}
......
......@@ -25,7 +25,7 @@ class Optimizer {
private static final int MAX_BRUTE_FORCE_FILTERS = 7;
private static final int MAX_BRUTE_FORCE = 2000;
private static final int MAX_GENETIC = 500;
private long start;
private long startNs;
private BitField switched;
// possible plans for filters, if using brute force:
......@@ -80,7 +80,7 @@ class Optimizer {
if (filters.length == 1 || session.isForceJoinOrder()) {
testPlan(filters);
} else {
start = System.nanoTime();
startNs = System.nanoTime();
if (filters.length <= MAX_BRUTE_FORCE_FILTERS) {
calculateBruteForceAll();
} else {
......@@ -98,7 +98,7 @@ class Optimizer {
private boolean canStop(int x) {
if ((x & 127) == 0) {
long t = System.nanoTime() - start;
long t = System.nanoTime() - startNs;
// don't calculate for simple queries (no rows or so)
if (cost >= 0 && 10 * t > cost * TimeUnit.MILLISECONDS.toNanos(1)) {
return true;
......
......@@ -102,7 +102,7 @@ public class Session extends SessionWithState {
private boolean redoLogBinary = true;
private boolean autoCommitAtTransactionEnd;
private String currentTransactionName;
private volatile long cancelAt;
private volatile long cancelAtNs;
private boolean closed;
private final long sessionStart = System.currentTimeMillis();
private long transactionStart;
......@@ -811,7 +811,7 @@ public class Session extends SessionWithState {
@Override
public void cancel() {
cancelAt = System.nanoTime();
cancelAtNs = System.nanoTime();
}
@Override
......@@ -1181,7 +1181,7 @@ public class Session extends SessionWithState {
if (queryTimeout > 0 && command != null) {
currentCommandStart = System.currentTimeMillis();
long now = System.nanoTime();
cancelAt = now + TimeUnit.MILLISECONDS.toNanos(queryTimeout);
cancelAtNs = now + TimeUnit.MILLISECONDS.toNanos(queryTimeout);
}
}
......@@ -1193,12 +1193,12 @@ public class Session extends SessionWithState {
*/
public void checkCanceled() {
throttle();
if (cancelAt == 0) {
if (cancelAtNs == 0) {
return;
}
long time = System.nanoTime();
if (time >= cancelAt) {
cancelAt = 0;
if (time >= cancelAtNs) {
cancelAtNs = 0;
throw DbException.get(ErrorCode.STATEMENT_WAS_CANCELED);
}
}
......@@ -1209,7 +1209,7 @@ public class Session extends SessionWithState {
* @return the time or 0 if not set
*/
public long getCancel() {
return cancelAt;
return cancelAtNs;
}
public Command getCurrentCommand() {
......@@ -1500,7 +1500,7 @@ public class Session extends SessionWithState {
this.queryTimeout = queryTimeout;
// must reset the cancel at here,
// otherwise it is still used
this.cancelAt = 0;
this.cancelAtNs = 0;
}
public int getQueryTimeout() {
......
......@@ -62,7 +62,7 @@ ShutdownHandler {
//*/
private Server web, tcp, pg;
private boolean isWindows;
private long lastOpen;
private long lastOpenNs;
/**
* When running without options, -tcp, -web, -browser and -pg are started.
......@@ -535,8 +535,8 @@ ShutdownHandler {
urlText.setText(url);
}
long now = System.nanoTime();
if (lastOpen == 0 || lastOpen + TimeUnit.MILLISECONDS.toNanos(100) < now) {
lastOpen = now;
if (lastOpenNs == 0 || lastOpenNs + TimeUnit.MILLISECONDS.toNanos(100) < now) {
lastOpenNs = now;
openBrowser(url);
}
}
......
......@@ -23,7 +23,7 @@ public class StringUtils {
private static SoftReference<String[]> softCache =
new SoftReference<String[]>(null);
private static long softCacheCreated;
private static long softCacheCreatedNs;
private static final char[] HEX = "0123456789abcdef".toCharArray();
private static final int[] HEX_DECODE = new int['f' + 1];
......@@ -64,7 +64,7 @@ public class StringUtils {
// create a new cache at most every 5 seconds
// so that out of memory exceptions are not delayed
long time = System.nanoTime();
if (softCacheCreated != 0 && time - softCacheCreated < TimeUnit.SECONDS.toNanos(5)) {
if (softCacheCreatedNs != 0 && time - softCacheCreatedNs < TimeUnit.SECONDS.toNanos(5)) {
return null;
}
try {
......@@ -72,7 +72,7 @@ public class StringUtils {
softCache = new SoftReference<String[]>(cache);
return cache;
} finally {
softCacheCreated = System.nanoTime();
softCacheCreatedNs = System.nanoTime();
}
}
......
......@@ -22,14 +22,14 @@ import org.h2.jdbc.JdbcConnection;
*/
public class ShowProgress implements DatabaseEventListener {
private final long start;
private long last;
private final long startNs;
private long lastNs;
/**
* Create a new instance of this class, and start the timer.
* Create a new instance of this class, and startNs the timer.
*/
public ShowProgress() {
start = last = System.nanoTime();
startNs = lastNs = System.nanoTime();
}
/**
......@@ -114,10 +114,10 @@ public class ShowProgress implements DatabaseEventListener {
@Override
public void setProgress(int state, String name, int current, int max) {
long time = System.nanoTime();
if (time < last + TimeUnit.SECONDS.toNanos(5)) {
if (time < lastNs + TimeUnit.SECONDS.toNanos(5)) {
return;
}
last = time;
lastNs = time;
String stateName = "?";
switch (state) {
case STATE_SCAN_FILE:
......@@ -140,7 +140,7 @@ public class ShowProgress implements DatabaseEventListener {
System.out.println("State: " + stateName + " " +
(100 * current / max) + "% (" +
current + " of " + max + ") "
+ TimeUnit.NANOSECONDS.toMillis(time - start) + " ms");
+ TimeUnit.NANOSECONDS.toMillis(time - startNs) + " ms");
}
/**
......
......@@ -36,7 +36,7 @@ class Database {
private String name, url, user, password;
private final ArrayList<String[]> replace = new ArrayList<String[]>();
private String currentAction;
private long startTime;
private long startTimeNs;
private Connection conn;
private Statement stat;
private long lastTrace;
......@@ -271,7 +271,7 @@ class Database {
*/
void start(Bench bench, String action) {
this.currentAction = bench.getName() + ": " + action;
this.startTime = System.nanoTime();
this.startTimeNs = System.nanoTime();
}
/**
......@@ -279,7 +279,7 @@ class Database {
* data.
*/
void end() {
long time = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
long time = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNs);
log(currentAction, "ms", (int) time);
if (test.isCollect()) {
totalTime += time;
......
......@@ -27,7 +27,7 @@ public class Profile extends Thread {
private boolean stop;
private int maxIndex;
private int lastIndex;
private long lastTime;
private long lastTimeNs;
private BufferedWriter trace;
private Profile() {
......@@ -38,7 +38,7 @@ public class Profile extends Thread {
maxIndex = r.getLineNumber();
count = new int[maxIndex];
time = new int[maxIndex];
lastTime = System.nanoTime();
lastTimeNs = System.nanoTime();
Runtime.getRuntime().addShutdownHook(this);
} catch (Exception e) {
e.printStackTrace();
......@@ -77,7 +77,7 @@ public class Profile extends Thread {
*/
public static void startCollecting() {
MAIN.stop = false;
MAIN.lastTime = System.nanoTime();
MAIN.lastTimeNs = System.nanoTime();
}
/**
......@@ -111,7 +111,7 @@ public class Profile extends Thread {
long now = System.nanoTime();
if (TRACE) {
if (trace != null) {
int duration = (int) TimeUnit.NANOSECONDS.toMillis(now - lastTime);
long duration = TimeUnit.NANOSECONDS.toMillis(now - lastTimeNs);
try {
trace.write(i + "\t" + duration + "\r\n");
} catch (Exception e) {
......@@ -121,8 +121,8 @@ public class Profile extends Thread {
}
}
count[i]++;
time[lastIndex] += (int) TimeUnit.NANOSECONDS.toMillis(now - lastTime);
lastTime = now;
time[lastIndex] += (int) TimeUnit.NANOSECONDS.toMillis(now - lastTimeNs);
lastTimeNs = now;
lastIndex = i;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论