All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.neo4j.kernel.api.query.QuerySnapshot Maven / Gradle / Ivy

Go to download

Neo4j kernel is a lightweight, embedded Java database designed to store data structured as graphs rather than tables. For more information, see http://neo4j.org.

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.kernel.api.query;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.neo4j.graphdb.ExecutionPlanDescription;
import org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo;
import org.neo4j.kernel.database.NamedDatabaseId;
import org.neo4j.lock.ActiveLock;
import org.neo4j.values.virtual.MapValue;

public class QuerySnapshot {
    private final ExecutingQuery query;
    private final CompilerInfo compilerInfo;
    private final long compilationTimeMicros;
    private final long elapsedTimeMicros;
    private final long cpuTimeMicros;
    private final long waitTimeMicros;
    private final String status;
    private final Map resourceInfo;
    private final List waitingLocks;
    private final long activeLockCount;
    private final long allocatedBytes;
    private final long pageHits;
    private final long pageFaults;
    private final Optional obfuscatedQueryText;
    private final Optional obfuscatedQueryParameters;
    private final long transactionId;
    private final long parentTransactionId;
    private final String parentDbName;
    private final QueryCacheUsage executableQueryCacheUsage;
    private final QueryCacheUsage logicalPlanCacheUsage;

    QuerySnapshot(
            ExecutingQuery query,
            CompilerInfo compilerInfo,
            long pageHits,
            long pageFaults,
            long compilationTimeMicros,
            long elapsedTimeMicros,
            long cpuTimeMicros,
            long waitTimeMicros,
            String status,
            Map resourceInfo,
            List waitingLocks,
            long activeLockCount,
            long allocatedBytes,
            Optional obfuscatedQueryText,
            Optional obfuscatedQueryParameters,
            long outerTransactionId,
            String parentDbName,
            long parentTransactionId,
            QueryCacheUsage executableQueryCacheUsage,
            QueryCacheUsage logicalPlanCacheUsage) {
        this.query = query;
        this.compilerInfo = compilerInfo;
        this.pageHits = pageHits;
        this.pageFaults = pageFaults;
        this.compilationTimeMicros = compilationTimeMicros;
        this.elapsedTimeMicros = elapsedTimeMicros;
        this.cpuTimeMicros = cpuTimeMicros;
        this.waitTimeMicros = waitTimeMicros;
        this.status = status;
        this.resourceInfo = resourceInfo;
        this.waitingLocks = waitingLocks;
        this.activeLockCount = activeLockCount;
        this.allocatedBytes = allocatedBytes;
        this.obfuscatedQueryText = obfuscatedQueryText;
        this.obfuscatedQueryParameters = obfuscatedQueryParameters;
        this.transactionId = outerTransactionId;
        this.parentDbName = parentDbName;
        this.parentTransactionId = parentTransactionId;
        this.executableQueryCacheUsage = executableQueryCacheUsage;
        this.logicalPlanCacheUsage = logicalPlanCacheUsage;
    }

    public long internalQueryId() {
        return query.internalQueryId();
    }

    public String id() {
        return query.id();
    }

    public String rawQueryText() {
        return query.rawQueryText();
    }

    public Optional obfuscatedQueryText() {
        return obfuscatedQueryText;
    }

    public MapValue rawQueryParameters() {
        return query.rawQueryParameters();
    }

    public Optional obfuscatedQueryParameters() {
        return obfuscatedQueryParameters;
    }

    public Supplier queryPlanSupplier() {
        return query.planDescriptionSupplier();
    }

    public String executingUsername() {
        return query.executingUsername();
    }

    public String authenticatedUsername() {
        return query.authenticatedUsername();
    }

    public Optional databaseId() {
        return query.databaseId();
    }

    public ClientConnectionInfo clientConnection() {
        return query.clientConnection();
    }

    public Map transactionAnnotationData() {
        return query.transactionAnnotationData();
    }

    public long activeLockCount() {
        return activeLockCount;
    }

    public String planner() {
        return compilerInfo == null ? null : compilerInfo.planner();
    }

    public String runtime() {
        return compilerInfo == null ? null : compilerInfo.runtime();
    }

    public List> indexes() {
        if (compilerInfo == null) {
            return Collections.emptyList();
        }
        return compilerInfo.indexes().stream().map(IndexUsage::asMap).collect(Collectors.toList());
    }

    public String status() {
        return status;
    }

    public Map resourceInformation() {
        return resourceInfo;
    }

    public long startTimestampMillis() {
        return query.startTimestampMillis();
    }

    /**
     * User transaction ID of the outer transaction that is executing this query.
     */
    public long transactionId() {
        return transactionId;
    }

    /**
     * The time spent planning the query, before the query actually starts executing.
     *
     * @return the time in microseconds spent planning the query.
     */
    public long compilationTimeMicros() {
        return compilationTimeMicros;
    }

    /**
     * The time that has been spent waiting on locks or other queries, as opposed to actively executing this query.
     *
     * @return the time in microseconds spent waiting on locks.
     */
    public long waitTimeMicros() {
        return waitTimeMicros;
    }

    /**
     * The time (wall time) that has elapsed since the execution of this query started.
     *
     * @return the time in microseconds since execution of this query started.
     */
    public long elapsedTimeMicros() {
        return elapsedTimeMicros;
    }

    /**
     * Time that the CPU has actively spent working on things related to this query.
     *
     * @return the time in microseconds that the CPU has spent on this query, or {@code null} if the cpu time could not
     * be measured.
     */
    public OptionalLong cpuTimeMicros() {
        return cpuTimeMicros < 0 ? OptionalLong.empty() : OptionalLong.of(cpuTimeMicros);
    }

    /**
     * Time from the start of this query that the computer spent doing other things than working on this query, even
     * though the query was runnable.
     * 

* In rare cases the idle time can be negative. This is due to the fact that the Thread does not go to sleep * immediately after we start measuring the wait-time, there is still some "lock bookkeeping time" that counts as * both cpu time (because the CPU is actually actively working on this thread) and wait time (because the query is * actually waiting on the lock rather than doing active work). In most cases such "lock bookkeeping time" is going * to be dwarfed by the idle time. * * @return the time in microseconds that this query was de-scheduled, or {@code null} if the cpu time could not be * measured. */ public OptionalLong idleTimeMicros() { return cpuTimeMicros < 0 ? OptionalLong.empty() : OptionalLong.of(elapsedTimeMicros - cpuTimeMicros - waitTimeMicros); } /** * The number of bytes allocated by the query. * * @return the number of bytes allocated by the execution of the query, or Optional.empty() if measurement was not possible or not enabled. */ public long allocatedBytes() { return allocatedBytes; } public long pageHits() { return pageHits; } public long pageFaults() { return pageFaults; } public List waitingLocks() { return waitingLocks; } public String parentDbName() { return parentDbName; } public long parentTransactionId() { return parentTransactionId; } public Optional executableQueryCacheUsage() { return Optional.ofNullable(executableQueryCacheUsage); } public Optional logicalPlanCacheUsage() { return Optional.ofNullable(logicalPlanCacheUsage); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy