コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
ファイル: Profiler.cs プロジェクト: volkd/nanoprofiler
        /// <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"));
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 /// <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);
 }
コード例 #8
0
 IProfiler IProfilerProvider.Start(string name, IProfilingStorage storage, IEnumerable<string> tags)
 {
     return Start(name, storage, tags);
 }