From 24bc5bce8a46416c7d9eb101427f39beea62a99e Mon Sep 17 00:00:00 2001 From: Donald Hutchison Date: Thu, 18 Jan 2024 18:33:30 +0100 Subject: [PATCH] Add logging to repo_helper to get timing info. --- apps/explorer/lib/explorer/repo/repo_helper.ex | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/repo/repo_helper.ex b/apps/explorer/lib/explorer/repo/repo_helper.ex index 292d7a94513d..3915ed94a92c 100644 --- a/apps/explorer/lib/explorer/repo/repo_helper.ex +++ b/apps/explorer/lib/explorer/repo/repo_helper.ex @@ -35,16 +35,32 @@ defmodule Explorer.Repo.RepoHelper do chunk_size = Keyword.get(opts, :chunk_size, @chunk_size) + chunks = ceil(length(elements) / chunk_size) + if chunks > 1 do + Logger.info("!!!! safe_insert_all #{kind |> to_string()} chunks #{chunks}") + end + + global_insert_start = System.monotonic_time() + elements |> Enum.chunk_every(chunk_size) |> Enum.reduce({0, []}, fn chunk, {total_count, acc} -> + local_insert_start = System.monotonic_time() + {count, inserted} = try do - __MODULE__.insert_all(kind, chunk, opts) + result = __MODULE__.insert_all(kind, chunk, opts) + if chunks > 1 do + local_insert_end = System.monotonic_time() + Logger.info("!!!! inserted #{kind |> to_string()} in #{local_insert_end - local_insert_start} (global #{local_insert_end - global_insert_start})") + end + result rescue exception -> old_truncate = Application.get_env(:logger, :truncate) Logger.configure(truncate: :infinity) + failed = System.monotonic_time() + Logger.info("!!!! failed #{kind |> to_string()} in #{failed - local_insert_start} (global #{failed - global_insert_start})") Logger.error(fn -> [