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