/// <summary> /// Starts new scope that will measure execution time of the operation /// with specified <paramref name="specification"/>.<br /> /// Uppon disposing will store the results of measurement in the current session.<br /> /// If there is no session started - returns dummy operation that will do nothing. /// </summary> public ProfileOperation Profile(ProfileOperationSpecification specification) { try { if (!this.Configuration.Enabled) { return(null); } var session = this.currentSession.Get(); ProfileOperation operation; if (session != null) { operation = session.StartMeasure(specification); } else { operation = new ProfileOperation(id: 0, profiler: this, session: null, specification: specification, parent: null); } return(operation); } catch (Exception ex) { this.logger.LogError(ex); return(null); } }
/// <summary> /// Starts new scope that will measure execution time of the operation /// with specified <paramref name="specification"/>.<br /> /// Uppon disposing will store the results of measurement in the specified <paramref name="session"/>.<br /> /// </summary> public ProfileOperation Profile(ProfileSession session, ProfileOperationSpecification specification) { if (session == null) { throw new ArgumentNullException(nameof(session)); } try { if (!this.Configuration.Enabled) { return(null); } var operation = session.StartMeasure(specification); return(operation); } catch (Exception ex) { this.logger.LogError(ex); return(null); } }
public static ProfileOperation Profile([NotNull] ProfileSession session, [NotNull] ProfileOperationSpecification specification) => ProfilerFactory.GetCurrentProfiler().Profile(session, specification);