Esempio n. 1
0
        public static PerformanceData EndTrace(string uri, TraceServer traceServerReader)
        {
            PerformanceData perf = new PerformanceData(uri);

            traceServerReader.Stop();

            while (traceServerReader.Read())
            {
                string ApplicationName = traceServerReader.GetString(2);
                if (ApplicationName == null)
                {
                    ApplicationName = string.Empty;
                }
                if (ApplicationName == "SQL Management")
                {
                    continue;
                }
                if (ApplicationName == "Microsoft SQL Server Management Studio")
                {
                    continue;
                }
                if (ApplicationName.StartsWith("SQL Server Profiler"))
                {
                    continue;
                }

                //0: EventClass
                //1: TextData
                //2: ApplicationName
                //3: NTUserName
                //4: LoginName
                //5: CPU
                //6: Reads
                //7: Writes
                //8: Duration
                //9: ClientProcessID
                //10: SPID
                //11: StartTime
                //12: EndTime
                //13: BinaryData

                //string query = traceServerReader.GetString(1);
                //if (string.IsNullOrEmpty(query)) query = string.Empty;
                //if (query.StartsWith("exec sp_executesql N'")) query = query.Remove(0, 21);
                // if (query.Length > 64) query = query.Substring(0, 64);

                //Console.WriteLine("{0}: {1} -> {2} | CPU={3} | Duration={4}", nEventNum,
                //    query,
                //    traceServerReader.GetString(2),
                //    traceServerReader.GetOrdinal("CPU"),
                //    traceServerReader.GetOrdinal("Duration"));

                perf.Queries++;
                object duration = traceServerReader.GetValue(8);
                perf.TotalDuration += (duration == null ? 0 : (long)duration);
            }

            return(perf);
        }
Esempio n. 2
0
        public void TestDeep(Cookie cookie, SqlConnectionInfo sci)
        {
            Uri root = new Uri("http://localhost/DBlog/Default.aspx");

            List <Uri> queue   = new List <Uri>(2500);
            List <Uri> visited = new List <Uri>(5000);

            PerformanceDataCollection perfdata = (sci == null ? null : new PerformanceDataCollection());

            double totaltime  = 0;
            int    totalcount = 0;

            queue.Add(root);

            Dictionary <Uri, Uri> references = new Dictionary <Uri, Uri>();

            references.Add(root, new Uri("http://localhost/DBlog/"));

            while (queue.Count > 0)
            {
                Uri            topofqueue = queue[0];
                List <HtmlUri> links;
                double         ts = 0;

                PerformanceData perf = (perfdata != null ? new PerformanceData(topofqueue.ToString()) : null);
                try
                {
                    TraceServer traceServerReader = (sci == null ? null : SqlTrace.BeginTrace(sci));
                    TestPage(references[topofqueue], topofqueue, cookie, out links, out ts);
                    if (perfdata != null)
                    {
                        perfdata.Add(SqlTrace.EndTrace(topofqueue.ToString(), traceServerReader));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    Console.WriteLine("{0}: {1}", topofqueue, ex.Message);
                    throw ex;
                }
                finally
                {
                    totalcount++;
                    totaltime += ts;
                    // add to visited links
                    visited.Add(topofqueue);
                    // remove from queue
                    queue.RemoveAt(0);
                }

                if (perfdata != null)
                {
                    perfdata.Add(perf);
                }

                // -----------------
                Console.Write("{0}/{1} [avg: {2}]", totalcount, queue.Count, (totaltime / totalcount).ToString("0.00"));
                if (perf != null)
                {
                    Console.Write("[SQL: {0} in {1}] ", perf.Queries, perf.TotalDuration);
                }
                Console.Write(" => ");

                int count = 0;
                foreach (HtmlUri uri in links)
                {
                    Uri fulluri = uri.Uri;

                    if (!root.IsBaseOf(fulluri))
                    {
                        // Console.WriteLine("\tSkipping {0}.", uri);
                        continue;
                    }

                    if (references.ContainsKey(fulluri) || queue.Contains(fulluri) || visited.Contains(fulluri))
                    {
                        continue;
                    }

                    Assert.IsFalse(fulluri.ToString().Contains("\0"),
                                   string.Format("Uri {0} in {1} contains non-ASCII character.", fulluri, topofqueue));

                    Assert.IsFalse(fulluri.ToString().Contains("<%"),
                                   string.Format("Uri {0} in {1} contains non-executed ASP.NET code.", fulluri, topofqueue));

                    Assert.IsFalse(fulluri.ToString().Contains("id=0"),
                                   string.Format("Uri {0} in {1} contains a link to a zero id.", fulluri, topofqueue));

                    references.Add(fulluri, topofqueue);

                    // Console.WriteLine("\tAdding {0}.", fulluri.OriginalString);
                    queue.Add(fulluri);
                    count++;
                }

                if ((perfdata != null) && (((totalcount > 0) && ((totalcount % 100) == 0)) || (queue.Count == 0)))
                {
                    perfdata.DumpPigs();
                }
            }
        }