/// <summary>
        /// Stops profiling for the given context, returns all IProfiledCommands associated.
        ///
        /// By default this may do a sweep for dead profiling contexts, you can disable this by passing "allowCleanupSweep: false".
        /// </summary>
        public ProfiledCommandEnumerable FinishProfiling(object forContext, bool allowCleanupSweep = true)
        {
            if (profiler == null)
            {
                throw new InvalidOperationException("Cannot begin profiling if no IProfiler has been registered with RegisterProfiler");
            }
            if (forContext == null)
            {
                throw new ArgumentNullException(nameof(forContext));
            }

            ProfiledCommandEnumerable ret;

            if (!profiledCommands.TryRemove(forContext, out ret))
            {
                throw ExceptionFactory.FinishedProfilingWithInvalidContext(forContext);
            }

            // conditional, because it could hurt and that may sometimes be unacceptable
            if (allowCleanupSweep)
            {
                profiledCommands.TryCleanup();
            }

            return(ret);
        }