public static WatchTime Get(string context, bool cumulative = false, bool nested = false) { WatchTime instance; lock (WatchTime.pool) { if (WatchTime.pool.Count > 0) { instance = WatchTime.pool.Pop(); } else { instance = new WatchTime(); } } if (nested == true) { instance.context = WatchTime.stack.Peek().context + context; } else { instance.context = context; } instance.cumulative = cumulative; instance.watch.Reset(); instance.watch.Start(); lock (WatchTime.stack) { WatchTime.stack.Push(instance); } return(instance); }
public static AssemblyUsagesResult[] CheckCompatibilities(IEnumerable <string> assembliesPath, FilterText[] filterNamespaces, string[] targetNamespaces, IEnumerable <string> unityVersions) { if (targetNamespaces.Length == 0) { Debug.LogWarning("You must target at least one namespace."); return(null); } int hash = 0; hash += assembliesPath.GetHashCode(); for (int i = 0, max = filterNamespaces.Length; i < max; ++i) { FilterText filter = filterNamespaces[i]; if (filter.active == true) { hash += filter.text.GetHashCode() + filter.active.GetHashCode(); } } for (int i = 0, max = targetNamespaces.Length; i < max; ++i) { hash += targetNamespaces[i].GetHashCode(); } if (AssemblyUsages.usages == null || AssemblyUsages.lastUsagesHash != hash) { AssemblyUsages.lastUsagesHash = hash; using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Extracted usages from target assemblies")) { AssemblyUsages.usages = AssemblyUsages.InspectAssembly(assembliesPath, filterNamespaces, targetNamespaces); } } List <AssemblyUsagesResult> results = new List <AssemblyUsagesResult>(); int processorCount = Environment.ProcessorCount; Exception threadException = null; DatabaseMeta database = DatabaseMeta.GetDatabase(); using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Resolving all")) { foreach (string unityVersion in unityVersions) { try { UnityMeta unityMeta = database.Get(unityVersion); if (unityMeta != null) { AssemblyUsagesResult result = new AssemblyUsagesResult() { assemblyUsages = usages, unityMeta = unityMeta }; using ((AssemblyUsages.debug & DebugItems.WatchTime) == 0 ? null : WatchTime.Get("Resolved against " + unityMeta.Version)) { result.ResolveReferences(AssemblyUsages.usages.visibleTypes, AssemblyUsages.usages.visibleFields, AssemblyUsages.usages.visibleMethods); } lock (results) { results.Add(result); } } } catch (Exception ex) { Debug.LogException(ex); threadException = ex; } } } if (threadException != null) { throw threadException; } results.Sort(Utility.CompareVersion); return(results.ToArray()); }