コード例 #1
0
ファイル: CacheActivity.cs プロジェクト: kittinap/kunnjae
        /// <summary>
        /// If the activity is in the Started state, calls Stop("Dispose").
        /// If the activity is in any other state, this is a no-op.
        /// Note that this class inherits from IDisposable to enable use in
        /// using blocks, not because it owns any unmanaged resources. It is
        /// not necessarily an error to abandon an activity without calling
        /// Dispose, especially if you call Stop directly.
        /// </summary>
        public void Dispose()
        {
            if (m_state == State.Started)
            {
                m_state = State.Stopped;

                if (m_enabled)
                {
                    if (m_mayTerminateEarly)
                    {
                        var finalData = new CacheETWData <string>()
                        {
                            CacheId = m_cacheId, Data = "Terminated Early"
                        };
                        m_eventSource.Write(m_activityName, ref m_options, ref m_id, ref m_relatedId, ref finalData);
                    }
                    else
                    {
                        var data = default(EmptyStruct);

                        // While we could use the activity name here and embed the "disposed" comment in the data, writing it as the
                        // event name makes testing for it easier, and we can still track back to the correct start call via the activityID.
                        m_eventSource.Write(DisposedEventName, ref m_options, ref m_id, ref m_relatedId, ref data);
                    }
                }
            }
        }
コード例 #2
0
ファイル: CacheActivity.cs プロジェクト: kittinap/kunnjae
        /// <summary>
        /// Writes an event associated with this activity.
        /// May only be called when the activity is in the Started state.
        /// </summary>
        /// <param name="options">
        /// The options to use for the event.
        /// </param>
        /// <param name="data">The data to include in the event.</param>
        public void Write <T>(EventSourceOptions options, T data)
        {
            var finalData = new CacheETWData <T>()
            {
                CacheId = m_cacheId, Data = data
            };

            Write(m_activityName, ref options, ref finalData);
        }
コード例 #3
0
ファイル: CacheActivity.cs プロジェクト: kittinap/kunnjae
        private void Stop <T>(string activityName, ref T data)
        {
            Contract.Requires(m_state == State.Started);

            m_state = State.Stopped;

            if (m_enabled)
            {
                var finalData = new CacheETWData <T>()
                {
                    CacheId = m_cacheId, Data = data
                };
                m_eventSource.Write(activityName, ref m_options, ref m_id, ref m_relatedId, ref finalData);
            }
        }
コード例 #4
0
ファイル: CacheActivity.cs プロジェクト: kittinap/kunnjae
        /// <summary>
        /// Writes a Start event with the data.
        /// </summary>
        /// <param name="data">The data to include in the event.</param>
        /// <remarks>
        /// May only be called when the activity is in the Initialized state.
        /// Sets the activity to the Started state.
        /// </remarks>
        private void Start <T>(T data)
        {
            Contract.Requires(m_state == State.Initialized);

            m_state = State.Started;

            if (m_enabled)
            {
                var finalData = new CacheETWData <T>()
                {
                    CacheId = m_cacheId, Data = data
                };
                var options = m_options;
                options.Opcode = EventOpcode.Start;
                m_eventSource.Write(m_activityName, ref options, ref m_id, ref m_relatedId, ref finalData);
            }
        }
コード例 #5
0
ファイル: CacheActivity.cs プロジェクト: kittinap/kunnjae
        private void Write <T>(string activityName, ref EventSourceOptions options, ref T data)
        {
            Contract.Requires(m_state == State.Started);

            if (m_enabled)
            {
                var finalData = new CacheETWData <T>()
                {
                    CacheId = m_cacheId, Data = data
                };
#if !FEATURE_CORECLR
                // Fails on .Net Standard build: System.ArgumentException: The API supports only anonymous types or types decorated with the EventDataAttribute. Non-compliant type: Failure dataType.
                // finalData seems to be the problematic argument
                m_eventSource.Write(activityName, ref options, ref m_id, ref m_relatedId, ref finalData);
#else
                m_eventSource.Write(activityName, options);
#endif
            }
        }