Created
February 27, 2017 23:31
-
-
Save myronmarston/8f42794daca161d97f3359e14ace3e86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ff210553f1a66db745a32224ff69b57073f953c6 Mon Sep 17 00:00:00 2001 | |
From: Myron Marston <[email protected]> | |
Date: Mon, 27 Feb 2017 15:01:27 -0800 | |
Subject: [PATCH] WIP: add monitor statements. | |
--- | |
lib/mix/lib/mix/dep/converger.ex | 120 ++++++++++++++++++++++----------------- | |
1 file changed, 67 insertions(+), 53 deletions(-) | |
diff --git a/lib/mix/lib/mix/dep/converger.ex b/lib/mix/lib/mix/dep/converger.ex | |
index c90f38a..aef8146 100644 | |
--- a/lib/mix/lib/mix/dep/converger.ex | |
+++ b/lib/mix/lib/mix/dep/converger.ex | |
@@ -47,68 +47,82 @@ defmodule Mix.Dep.Converger do | |
See `Mix.Dep.Loader.children/1` for options. | |
""" | |
def converge(acc, lock, opts, callback) do | |
- {deps, acc, lock} = all(acc, lock, opts, callback) | |
- if remote = Mix.RemoteConverger.get, do: remote.post_converge() | |
- {topsort(deps), acc, lock} | |
+ monitor "converge/4", fn -> | |
+ {deps, acc, lock} = all(acc, lock, opts, callback) | |
+ if remote = Mix.RemoteConverger.get, do: monitor("remote.post_converge()", fn -> remote.post_converge() end) | |
+ {topsort(deps), acc, lock} | |
+ end | |
+ end | |
+ | |
+ defp monitor(label, action) do | |
+ {micro_secs, value} = :timer.tc(action) | |
+ Mix.Shell.IO.info("#{label} took #{micro_secs / 1000} ms") | |
+ value | |
end | |
defp all(acc, lock, opts, callback) do | |
- main = Mix.Dep.Loader.children() | |
- main = Enum.map(main, &(%{&1 | top_level: true})) | |
- apps = Enum.map(main, &(&1.app)) | |
- | |
- lock_given? = !!lock | |
- env = opts[:env] | |
- | |
- # If no lock was given, let's read one to fill in the deps | |
- lock = lock || Mix.Dep.Lock.read | |
- | |
- # Run converger for all dependencies, except remote | |
- # dependencies. Since the remote converger may be | |
- # lazily loaded, we need to check for it on every | |
- # iteration. | |
- {deps, rest, lock} = | |
- all(main, apps, callback, acc, lock, env, fn dep -> | |
- if (remote = Mix.RemoteConverger.get) && remote.remote?(dep) do | |
- {:loaded, dep} | |
- else | |
- {:unloaded, dep, nil} | |
- end | |
- end) | |
+ monitor "all/4", fn -> | |
+ main = Mix.Dep.Loader.children() | |
+ main = Enum.map(main, &(%{&1 | top_level: true})) | |
+ apps = Enum.map(main, &(&1.app)) | |
+ | |
+ lock_given? = !!lock | |
+ env = opts[:env] | |
+ | |
+ # If no lock was given, let's read one to fill in the deps | |
+ lock = lock || Mix.Dep.Lock.read | |
- # Run remote converger and rerun Mix's converger with the new information. | |
- # Don't run the remote if deps didn't converge, if the remote is not | |
- # available or if none of the deps are handled by the remote. | |
- remote = Mix.RemoteConverger.get | |
- diverged? = Enum.any?(deps, &Mix.Dep.diverged?/1) | |
- use_remote? = !!remote and Enum.any?(deps, &remote.remote?/1) | |
- | |
- if not diverged? and use_remote? do | |
- # If there is a lock, it means we are doing a get/update | |
- # and we need to hit the remote converger which do external | |
- # requests and what not. In case of deps.loadpaths, deps and so | |
- # on, there is no lock, so we won't hit this branch. | |
- lock = if lock_given?, do: remote.converge(deps, lock), else: lock | |
- | |
- deps = deps | |
- |> Enum.reject(&remote.remote?(&1)) | |
- |> Enum.into(%{}, &{&1.app, &1}) | |
- | |
- # In case no lock was given, we will use the local lock | |
- # which is potentially stale. So remote.deps/2 needs to always | |
- # check if the data it finds in the lock is actually valid. | |
+ # Run converger for all dependencies, except remote | |
+ # dependencies. Since the remote converger may be | |
+ # lazily loaded, we need to check for it on every | |
+ # iteration. | |
{deps, rest, lock} = | |
- all(main, apps, callback, rest, lock, env, fn dep -> | |
- if cached = deps[dep.app] do | |
- {:loaded, cached} | |
+ all(main, apps, callback, acc, lock, env, fn dep -> | |
+ if (remote = Mix.RemoteConverger.get) && remote.remote?(dep) do | |
+ {:loaded, dep} | |
else | |
- {:unloaded, dep, remote.deps(dep, lock)} | |
+ {:unloaded, dep, nil} | |
end | |
end) | |
- {reject_non_fulfilled_optional(deps), rest, lock} | |
- else | |
- {reject_non_fulfilled_optional(deps), rest, lock} | |
+ # Run remote converger and rerun Mix's converger with the new information. | |
+ # Don't run the remote if deps didn't converge, if the remote is not | |
+ # available or if none of the deps are handled by the remote. | |
+ remote = Mix.RemoteConverger.get | |
+ diverged? = Enum.any?(deps, &Mix.Dep.diverged?/1) | |
+ use_remote? = !!remote and Enum.any?(deps, &remote.remote?/1) | |
+ | |
+ if not diverged? and use_remote? do | |
+ # If there is a lock, it means we are doing a get/update | |
+ # and we need to hit the remote converger which do external | |
+ # requests and what not. In case of deps.loadpaths, deps and so | |
+ # on, there is no lock, so we won't hit this branch. | |
+ lock = monitor "lock_given?/remote.converge", fn -> | |
+ if lock_given?, do: remote.converge(deps, lock), else: lock | |
+ end | |
+ | |
+ deps = deps | |
+ |> Enum.reject(&remote.remote?(&1)) | |
+ |> Enum.into(%{}, &{&1.app, &1}) | |
+ | |
+ # In case no lock was given, we will use the local lock | |
+ # which is potentially stale. So remote.deps/2 needs to always | |
+ # check if the data it finds in the lock is actually valid. | |
+ {deps, rest, lock} = | |
+ monitor "get {deps, rest, lock} from all/7", fn -> | |
+ all(main, apps, callback, rest, lock, env, fn dep -> | |
+ if cached = deps[dep.app] do | |
+ {:loaded, cached} | |
+ else | |
+ {:unloaded, dep, remote.deps(dep, lock)} | |
+ end | |
+ end) | |
+ end | |
+ | |
+ {reject_non_fulfilled_optional(deps), rest, lock} | |
+ else | |
+ {reject_non_fulfilled_optional(deps), rest, lock} | |
+ end | |
end | |
end | |
-- | |
2.7.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment