Add tracing for time that is spent on read/write of account patch reviews

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: If0802166af6634ed3d5a58316a85a7260375a534
This commit is contained in:
Edwin Kempin
2019-07-15 09:11:43 +02:00
parent e017a1fe4c
commit bfd5191fb3
3 changed files with 56 additions and 6 deletions

View File

@@ -56,6 +56,9 @@ public abstract class Metadata {
// The value of the @Export annotation which was used to register a plugin extension.
public abstract Optional<String> exportValue();
// Path of a file in a repository.
public abstract Optional<String> filePath();
// Garbage collector name.
public abstract Optional<String> garbageCollectorName();
@@ -98,6 +101,9 @@ public abstract class Metadata {
// Name of a "table" in NoteDb (if set, always CHANGES).
public abstract Optional<String> noteDbTable();
// The ID of a patch set.
public abstract Optional<Integer> patchSetId();
// Plugin metadata that doesn't fit into any other category.
public abstract ImmutableList<PluginMetadata> pluginMetadata();
@@ -154,6 +160,8 @@ public abstract class Metadata {
public abstract Builder exportValue(@Nullable String exportValue);
public abstract Builder filePath(@Nullable String filePath);
public abstract Builder garbageCollectorName(@Nullable String garbageCollectorName);
public abstract Builder gitOperation(@Nullable String gitOperation);
@@ -182,6 +190,8 @@ public abstract class Metadata {
public abstract Builder noteDbTable(@Nullable String noteDbTable);
public abstract Builder patchSetId(int patchSetId);
abstract ImmutableList.Builder<PluginMetadata> pluginMetadataBuilder();
public Builder addPluginMetadata(PluginMetadata pluginMetadata) {

View File

@@ -15,6 +15,7 @@ java_library(
"//java/com/google/gerrit/metrics",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/logging",
"//java/com/google/gerrit/server/util/time",
"//lib:guava",
"//lib/auto:auto-value",

View File

@@ -34,6 +34,9 @@ import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.config.ThreadSettingsConfig;
import com.google.gerrit.server.logging.Metadata;
import com.google.gerrit.server.logging.TraceContext;
import com.google.gerrit.server.logging.TraceContext.TraceTimer;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -212,7 +215,15 @@ public abstract class JdbcAccountPatchReviewStore
@Override
public boolean markReviewed(PatchSet.Id psId, Account.Id accountId, String path) {
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Mark file as reviewed",
Metadata.builder()
.patchSetId(psId.get())
.accountId(accountId.get())
.filePath(path)
.build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement(
"INSERT INTO account_patch_reviews "
@@ -239,7 +250,15 @@ public abstract class JdbcAccountPatchReviewStore
return;
}
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Mark files as reviewed",
Metadata.builder()
.patchSetId(psId.get())
.accountId(accountId.get())
.resourceCount(paths.size())
.build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement(
"INSERT INTO account_patch_reviews "
@@ -264,7 +283,15 @@ public abstract class JdbcAccountPatchReviewStore
@Override
public void clearReviewed(PatchSet.Id psId, Account.Id accountId, String path) {
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Clear reviewed flag",
Metadata.builder()
.patchSetId(psId.get())
.accountId(accountId.get())
.filePath(path)
.build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement(
"DELETE FROM account_patch_reviews "
@@ -282,7 +309,11 @@ public abstract class JdbcAccountPatchReviewStore
@Override
public void clearReviewed(PatchSet.Id psId) {
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Clear all reviewed flags of patch set",
Metadata.builder().patchSetId(psId.get()).build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement(
"DELETE FROM account_patch_reviews "
@@ -297,7 +328,11 @@ public abstract class JdbcAccountPatchReviewStore
@Override
public void clearReviewed(Change.Id changeId) {
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Clear all reviewed flags of change",
Metadata.builder().changeId(changeId.get()).build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement("DELETE FROM account_patch_reviews WHERE change_id = ?")) {
stmt.setInt(1, changeId.get());
@@ -309,7 +344,11 @@ public abstract class JdbcAccountPatchReviewStore
@Override
public Optional<PatchSetWithReviewedFiles> findReviewed(PatchSet.Id psId, Account.Id accountId) {
try (Connection con = ds.getConnection();
try (TraceTimer ignored =
TraceContext.newTimer(
"Find reviewed flags",
Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).build());
Connection con = ds.getConnection();
PreparedStatement stmt =
con.prepareStatement(
"SELECT patch_set_id, file_name FROM account_patch_reviews APR1 "