/// <summary> /// Initializes a <see cref="Profiler"/> class instance. /// </summary> /// <param name="name">The profiler name.</param> /// <param name="storage">The profiler storage.</param> /// <param name="tags">Tags of the profiler.</param> public Profiler(string name, IProfilingStorage storage, TagCollection tags) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (storage == null) { throw new ArgumentNullException("storage"); } _storage = storage; _stopwatch = new Stopwatch(); _stopwatch.Start(); DateTime now = DateTime.Now; if (ConfigurationHelper.LoadPureProfilerConfigurationSection().EnableUtcTime) { now = DateTime.UtcNow; } _timingSession = new TimingSession(this, name, tags) { Started = now }; var rootTiming = new ProfilingStep(this, "root", null); _timingSession.AddTiming(rootTiming); }
/// <summary> /// Initializes a <see cref="CircularBufferedProfilingStorage"/>. /// </summary> /// <param name="size">The size of the circular buffer.</param> /// <param name="shouldBeExcluded">Whether or not, a <see cref="IProfiler"/> should not be saved in circular buffer.</param> /// <param name="wrappedStorage"> /// An optional <see cref="IProfilingStorage"/> instance to be wrapped. /// If wrappedStorage is specified, <see cref="CircularBufferedProfilingStorage"/> calls /// wrappedStorage.SaveResult() before saving to internal circular buffer. /// </param> public CircularBufferedProfilingStorage(int size = 100, Func<IProfiler, bool> shouldBeExcluded = null, IProfilingStorage wrappedStorage = null) { _size = size; _shouldBeExcluded = shouldBeExcluded; _wrappedStorage = wrappedStorage; // set Instance to be accessed by NanoProfilerModule for view-result feature Instance = this; }
static ProfilingSession() { // by default, use CallContextProfilingSessionContainer _profilingSessionContainer = new CallContextProfilingSessionContainer(); // by default, use JsonProfilingStorage _profilingStorage = new NoOperationProfilingStorage(); // intialize filters ProfilingFilters = new ProfilingFilterList(new List <IProfilingFilter>()); InitializeConfigurationFromConfig(); }
/// <summary> /// Starts a profiling session. /// </summary> /// <param name="name">The name of the profiler.</param> /// <param name="storage">The profiler storage.</param> /// <param name="tags">Tags of the profiler to be started.</param> /// <returns>Returns the started <see cref="IProfiler"/>.</returns> public IProfiler Start(string name, IProfilingStorage storage, IEnumerable<string> tags) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (storage == null) { throw new ArgumentNullException("storage"); } return CreateProfiler(name, storage, tags); }
/// <summary> /// Initializes a <see cref="Profiler"/> class instance. /// </summary> /// <param name="name">The profiler name.</param> /// <param name="storage">The profiler storage.</param> /// <param name="tags">Tags of the profiler.</param> public Profiler(string name, IProfilingStorage storage, IEnumerable<string> tags) : base("session", name) { if (storage == null) { throw new ArgumentNullException("storage"); } _storage = storage; Tags = (tags == null ? null : new TagCollection(tags)); _started = DateTime.UtcNow; _stopwatch = new Stopwatch(); _stopwatch.Start(); _stepTimings = new ConcurrentQueue<StepTiming>(); _customTimings = new ConcurrentQueue<CustomTiming>(); _stepTimings.Enqueue(new StepTiming(this, "root")); }
/// <summary> /// Initializes a <see cref="Profiler"/> class instance. /// </summary> /// <param name="name">The profiler name.</param> /// <param name="storage">The profiler storage.</param> /// <param name="tags">Tags of the profiler.</param> public Profiler(string name, IProfilingStorage storage, TagCollection tags) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (storage == null) { throw new ArgumentNullException("storage"); } _storage = storage; _stopwatch = new Stopwatch(); _stopwatch.Start(); _timingSession = new TimingSession(this, name, tags) { Started = DateTime.UtcNow }; var rootTiming = new ProfilingStep(this, "root", null); _timingSession.AddTiming(rootTiming); }
/// <summary> /// Creates a <see cref="IProfiler"/> instance. /// </summary> /// <param name="name">The name of the profiler.</param> /// <param name="storage">The profiler storage.</param> /// <param name="tags">Tags of the profiler to be started.</param> /// <returns>Returns the created <see cref="IProfiler"/>.</returns> protected virtual Profiler CreateProfiler( string name, IProfilingStorage storage, IEnumerable<string> tags) { return new Profiler(name, storage, tags); }
IProfiler IProfilerProvider.Start(string name, IProfilingStorage storage, IEnumerable<string> tags) { return Start(name, storage, tags); }