presto-main/src/main/java/io/prestosql/execution/QueryManagerStats.java/StatisticsListener/stateChanged
class StatisticsListener:        @Override
        public void stateChanged(QueryState newValue)
        {
            synchronized (this) {
                if (stopped) {
                    return;
                }

                if (newValue.isDone()) {
                    stopped = true;
                    if (started) {
                        queryStopped();
                    }
                    finalQueryInfoSupplier.get()
                            .ifPresent(QueryManagerStats.this::queryFinished);
                }
                else if (newValue.ordinal() >= RUNNING.ordinal()) {
                    if (!started) {
                        started = true;
                        queryStarted();
                    }
                }
            }
        }