1 //------------------------------------------------------------------------------
2 // <copyright file="Profiler.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
10 * Copyright (c) 2000 Microsoft Corporation
13 namespace System.Web.Util {
17 using System.Web.SessionState;
19 using System.Threading;
20 using System.Collections;
22 internal class Profiler {
23 private int _requestsToProfile;
24 private Queue _requests;
25 private bool _pageOutput;
26 private bool _isEnabled;
27 private bool _oldEnabled;
28 private bool _localOnly;
29 private bool _mostRecent;
30 private TraceMode _outputMode;
34 _requestsToProfile = 10;
35 _outputMode = TraceMode.SortByTime;
38 _requests = new Queue(_requestsToProfile);
41 internal bool IsEnabled {
42 get { return _isEnabled;}
49 internal bool PageOutput {
51 // calling HttpContext.Current is slow, but we'll only get there if _pageOutput is true.
52 return (_pageOutput && !(_localOnly && !HttpContext.Current.Request.IsLocal));
59 internal TraceMode OutputMode {
60 get { return _outputMode;}
61 set { _outputMode = value;}
64 internal bool LocalOnly {
65 get { return _localOnly;}
66 set { _localOnly = value; }
69 internal bool MostRecent {
70 get { return _mostRecent; }
71 set { _mostRecent = value; }
74 internal bool IsConfigEnabled {
75 get { return _oldEnabled; }
78 internal int RequestsToProfile {
79 get { return _requestsToProfile;}
81 // VSWhidbey195368 Silently cap request limit at 10,000
85 _requestsToProfile = value;
89 internal int RequestsRemaining {
90 get { return _requestsToProfile - _requests.Count;}
93 internal void Reset() {
94 // start profiling and clear the current log of requests
95 _requests = new Queue(_requestsToProfile);
97 if (_requestsToProfile != 0)
98 _isEnabled = _oldEnabled;
103 internal void StartRequest(HttpContext context) {
104 context.Trace.VerifyStart();
107 internal void EndRequest(HttpContext context) {
108 context.Trace.EndRequest();
110 // Don't add the trace data if we aren't enabled
111 if (!IsEnabled) return;
113 // grab trace data and add it to the list
115 _requests.Enqueue(context.Trace.GetData());
117 // If we are storing the most recent, we may need to kick out the first request
119 if (_requests.Count > _requestsToProfile) _requests.Dequeue();
123 // Turn off profiling if we are only tracking the first N requests and we hit the limit.
124 if (!MostRecent && _requests.Count >= _requestsToProfile) EndProfiling();
127 internal void EndProfiling() {
131 internal IList GetData() {
132 return _requests.ToArray();