Exemple #1
0
        /// <summary>
        /// Log the test
        /// </summary>
        /// <param name="request">Request</param>
        /// <param name="perfLog">PerfLog</param>
        void LogToConsole(Request request, ValidationResult valid, PerfLog perfLog)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (valid == null)
            {
                throw new ArgumentNullException(nameof(valid));
            }

            if (perfLog == null)
            {
                throw new ArgumentNullException(nameof(perfLog));
            }

            // only log 4XX and 5XX status codes unless verbose is true or there were validation errors
            if ((config.Verbose) || perfLog.StatusCode > 399 || valid.Failed || valid.ValidationErrors.Count > 0)
            {
                string log = string.Format(System.Globalization.CultureInfo.InvariantCulture, $"{DateTime.UtcNow.ToString("MM/dd hh:mm:ss", CultureInfo.InvariantCulture)}\t{perfLog.StatusCode}\t{perfLog.Duration}\t{perfLog.Category.PadRight(12).Substring(0, 12)}\t{perfLog.PerfLevel}\t{perfLog.Validated}\t{perfLog.ContentLength}\t{request.Path}");

                if (valid.Failed)
                {
                    log += "\tFAILED";
                }

                if (valid.ValidationErrors.Count > 0)
                {
                    log += "\t" + string.Join('\t', valid.ValidationErrors);
                }

                Console.WriteLine(log);
            }
        }
Exemple #2
0
        async Task AutomatedTests()
        {
            if (_automated)
            {
                if (_currentTest >= _tests.Count)
                {
                    _currentTest = 0;
                    ++_currentLoop;

                    if (_currentLoop >= _loops)
                    {
                        _automated         = false;
                        TestList.IsEnabled = true;

                        MarkTestsAsFinishedForUITests();
                        Summary.Text  = "Summary: " + Environment.NewLine;
                        Summary.Text += PerfLog.Summary();
                    }
                }

                if (_currentLoop < _loops)
                {
                    Summary.Text = $"Tests in progress ({_currentLoop + 1}/{_loops})";

                    TestList.IsEnabled = false;
                    await GoToTest(_tests[_currentTest++]);
                }
            }
        }
Exemple #3
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Xamarin.Calabash.Start();
            PerfLog.MeasureStart("First Page Load");
            PerfLog.Measure("App Init", () => global::Xamarin.Forms.Forms.Init());
            PerfLog.Measure("App Load", () => LoadApplication(new App()));

            return(base.FinishedLaunching(app, options));
        }
        protected async void EndTest()
        {
            PerfLog.MeasureStop(GetType().Name);

            if (_automated)
            {
                await Navigation.PopAsync();
            }
        }
Exemple #5
0
        /// <summary>
        /// Log the test
        /// </summary>
        /// <param name="request">Request</param>
        /// <param name="perfLog">PerfLog</param>
        private void LogToConsole(Request request, ValidationResult valid, PerfLog perfLog)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (valid == null)
            {
                throw new ArgumentNullException(nameof(valid));
            }

            if (perfLog == null)
            {
                throw new ArgumentNullException(nameof(perfLog));
            }

            // don't log ignore requests
            if (request.PerfTarget?.Category != "Ignore")
            {
                Dictionary <string, object> logDict = new Dictionary <string, object>
                {
                    { "Date", perfLog.Date },
                    { "Server", perfLog.Server },
                    { "StatusCode", perfLog.StatusCode },
                    { "Verb", request.Verb },
                    { "Path", perfLog.Path },
                    { "Errors", perfLog.ErrorCount },
                    { "Duration", Math.Round(perfLog.Duration, 2) },
                    { "ContentLength", perfLog.ContentLength },
                    { "CVector", perfLog.CorrelationVector },
                    { "CVectorBase", perfLog.CorrelationVectorBase },
                    { "Tag", perfLog.Tag },
                    { "Quartile", perfLog.Quartile },
                    { "Category", perfLog.Category },
                };

                // log error details
                if (config.VerboseErrors && valid.ValidationErrors.Count > 0)
                {
                    string errors = string.Empty;

                    // add up to 5 detailed errors
                    int max = valid.ValidationErrors.Count > 5 ? 5 : valid.ValidationErrors.Count;

                    for (int i = 0; i < max; i++)
                    {
                        errors += valid.ValidationErrors[i].Trim() + "\t";
                    }

                    logDict.Add("ErrorDetails", errors.Trim());
                }

                Console.WriteLine(JsonSerializer.Serialize(logDict, JsonOptions));
            }
        }
Exemple #6
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            PerfLog.MeasureStop(GetType().Name);

            if (_automated)
            {
                await Navigation.PopAsync();
            }
        }
Exemple #7
0
        public async Task <PerfLog> GetById(int perfLogId)
        {
            PerfLog result = null;
            await _retryPolicy.ExecuteAsync(async() =>
            {
                result = await _context.PerfLogs.FirstOrDefaultAsync(x => x.Id == perfLogId);
            });

            return(result);
        }
Exemple #8
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            PerfLog.MeasureStop("First Page Load");

            await Task.Delay(100);

            await AutomatedTests();
        }
Exemple #9
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            PerfLog.MeasureStart("First Page Load");
            PerfLog.Measure("App Init", () => global::Xamarin.Forms.Forms.Init(this, bundle));
            PerfLog.Measure("App Load", () => LoadApplication(new App()));
        }
        public void PerfLogTest()
        {
            var p = new PerfLog
            {
                Date = new System.DateTime(2020, 1, 1),
                ValidationResults = "test"
            };

            // validate getters and setters
            Assert.Equal(new System.DateTime(2020, 1, 1), p.Date);
            Assert.Equal("test", p.ValidationResults);
        }
Exemple #11
0
    public static void StaticLogs()
    {
        PerfLog.S();

        Log.D("Debug-");
        Log.I("Info-");
        Log.W("Warn-");
        Log.E("Error-");

        PerfLog.L("Test#StaticLogs");
        PerfLog.E();
    }
Exemple #12
0
        public void PerfLogTest()
        {
            PerfLog p = new PerfLog(new List <string> {
                "test"
            })
            {
                Date = new System.DateTime(2020, 1, 1)
            };

            // validate getters and setters
            Assert.Equal(new System.DateTime(2020, 1, 1), p.Date);
            Assert.Single(p.Errors);
            Assert.Equal("test", p.Errors[0]);
        }
Exemple #13
0
        /// <summary>
        /// Create a PerfLog
        /// </summary>
        /// <param name="server">server URL</param>
        /// <param name="request">Request</param>
        /// <param name="validationResult">validation errors</param>
        /// <param name="duration">duration</param>
        /// <param name="contentLength">content length</param>
        /// <param name="statusCode">status code</param>
        /// <returns>PerfLog</returns>
        public PerfLog CreatePerfLog(string server, Request request, ValidationResult validationResult, double duration, long contentLength, int statusCode)
        {
            if (validationResult == null)
            {
                throw new ArgumentNullException(nameof(validationResult));
            }

            // map the parameters
            PerfLog log = new PerfLog(validationResult.ValidationErrors)
            {
                Server        = server,
                Tag           = config.Tag,
                Path          = request?.Path ?? string.Empty,
                StatusCode    = statusCode,
                Category      = request?.PerfTarget?.Category ?? string.Empty,
                Validated     = !validationResult.Failed && validationResult.ValidationErrors.Count == 0,
                Duration      = duration,
                ContentLength = contentLength,
                Failed        = validationResult.Failed,
            };

            // determine the Performance Level based on category
            if (targets.ContainsKey(log.Category))
            {
                // lookup the target
                PerfTarget target = targets[log.Category];

                if (target != null &&
                    !string.IsNullOrEmpty(target.Category) &&
                    target.Quartiles != null &&
                    target.Quartiles.Count == 3)
                {
                    // set to max
                    log.Quartile = target.Quartiles.Count + 1;

                    for (int i = 0; i < target.Quartiles.Count; i++)
                    {
                        // find the lowest Perf Target achieved
                        if (duration <= target.Quartiles[i])
                        {
                            log.Quartile = i + 1;
                            break;
                        }
                    }
                }
            }

            return(log);
        }
Exemple #14
0
    public Test Logs()
    {
        var p = new PerfLog();

        p.Start();

        Log.D("Debug--");
        Log.I("Info--");
        Log.W("Warn--");
        Log.E("Error--");

        p.Elapsed("Test#Logs");
        p.Stop();

        return(this);
    }
Exemple #15
0
    public Test AnotherLog()
    {
        var p = new PerfLog();

        p.Start();

        DF("Debug---");
        IF("Info---");
        WF("Warn---");
        EF("Error---");

        p.Wrap("Test#AnotherLog", "test/another.log");
        p.Stop();

        return(this);
    }
Exemple #16
0
        public static string GetMode(PerfLog perfLog, out string category)
        {
            category = string.IsNullOrEmpty(perfLog.Category) ? string.Empty : perfLog.Category;

            string mode = category;
            string path = perfLog.Path.ToLower();

            if (mode.StartsWith("Genre") ||
                mode.StartsWith("Rating") ||
                mode.StartsWith("Year"))
            {
                category = "Movies";
                mode     = "Query";
            }
            else if (perfLog.Path.Contains("movies"))
            {
                category = "Movies";
            }
            else if (path.Contains("featured"))
            {
                category = "Movies";
            }
            else if (path.Contains("actors"))
            {
                category = "Actors";
            }
            else if (path.Contains("genres"))
            {
                category = "Genres";
                mode     = "Query";
            }
            else if (path.Contains("healthz"))
            {
                category = "Healthz";
                mode     = "Healthz";
            }

            if (mode.ToLowerInvariant().StartsWith("search") ||
                mode.ToLowerInvariant().StartsWith("paged"))
            {
                mode = "Query";
            }

            return(mode);
        }
Exemple #17
0
        static void Main(string[] args)
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += (o, e) =>
                {
                    Log.O(((Exception)e.ExceptionObject).ToString());
                };

                Log.LogFile = "test/result.log";

                var testcount = 1001;
                var test      = new Test();

                if (null != args && args.Length > 0)
                {
                    int.TryParse(args[0], out testcount);
                }
                Log.O($"Test count: {testcount}");

                var p = new PerfLog();
                p.Start();

                for (var i = 0; i < testcount; i++)
                {
                    Log.LogLevel = Log.Level.DEBUG;
                    Log.D("Hello bugs");
                    Log.I("For your information");
                    Log.W("Caution, the sky is falling.");
                    Log.E("Oh what's wrong, the sky fell.");

                    Test.StaticLogs();
                    test.Logs().AnotherLog();
                }

                p.Wrap("Test#Program");
                p.Stop();

                Log.O("Test ended.");
            }
            catch (Exception e)
            {
                Log.E(e.ToString());
            }
        }
Exemple #18
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                PerfLog.MeasureStart("First Page Load");
                PerfLog.Measure("App Init", () => Xamarin.Forms.Forms.Init(e));

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Exemple #19
0
        public Size Reflow(DrawContext dc, XmlElement e)
        {
            PerfLog.Mark();

            Style s = Stylesheet.GetStyle(dc.Graphics, e, dc.DocumentType.GetElementType(e));

            rootBlock = s.CreateReflowObject(null, e) as IBlock;
            if (rootBlock == null)
            {
                // TODO: M: exception handling
                throw new ArgumentException("Invalid stylesheet / document. Root element must be a block.");
            }

            BoundingContext bounds = new BoundingContext(dc.BoundingRectangle);

            Console.WriteLine("Root block reflow {0}", bounds);
            rootBlock.Reflow(dc, bounds, false);

            PerfLog.Write("Reflow complete for '{0}'", e.Name);
            return(new Size(rootBlock.Width, rootBlock.Height));
        }
Exemple #20
0
        private static string GetMode(PerfLog perfLog)
        {
            string mode = string.IsNullOrEmpty(perfLog.Category) ? string.Empty : perfLog.Category;
            string path = perfLog.Path.ToLower();

            if (path.Contains("healthz"))
            {
                mode = "Healthz";
            }
            else if (mode.StartsWith("Genre") ||
                     mode.StartsWith("Rating") ||
                     mode.StartsWith("Year") ||
                     path.Contains("genres") ||
                     mode.ToLowerInvariant().StartsWith("search") ||
                     mode.ToLowerInvariant().StartsWith("paged"))
            {
                mode = "Query";
            }

            return(mode == "DirectRead" ? "Direct" : mode);
        }
Exemple #21
0
        /// <summary>
        /// Log the test
        /// </summary>
        /// <param name="request">Request</param>
        /// <param name="perfLog">PerfLog</param>
        private void LogToConsole(Request request, ValidationResult valid, PerfLog perfLog)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (valid == null)
            {
                throw new ArgumentNullException(nameof(valid));
            }

            if (perfLog == null)
            {
                throw new ArgumentNullException(nameof(perfLog));
            }

            // don't log ignore requests
            if (request.PerfTarget?.Category != "Ignore")
            {
                Dictionary <string, object> logDict = new Dictionary <string, object>
                {
                    { "Date", perfLog.Date },
                    { "Server", perfLog.Server },
                    { "StatusCode", perfLog.StatusCode },
                    { "Verb", request.Verb },
                    { "Path", perfLog.Path },
                    { "Errors", perfLog.ErrorCount },
                    { "Duration", Math.Round(perfLog.Duration, 2) },
                    { "ContentLength", perfLog.ContentLength },
                    { "CVector", perfLog.CorrelationVector },
                    { "Tag", perfLog.Tag },
                    { "Quartile", perfLog.Quartile },
                    { "Category", perfLog.Category },
                    { "Region", App.Region },
                    { "Zone", App.Zone },
                    { "PodType", App.PodType },
                };

                // log trace header
                if (perfLog.Trace != null && perfLog.Trace.Any())
                {
                    try
                    {
                        Dictionary <string, object> trace = JsonSerializer.Deserialize <Dictionary <string, object> >(perfLog.Trace.First());

                        // log each item in order
                        foreach (string k in trace.Keys)
                        {
                            logDict.Add(k, trace[k]);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"TraceLog Exception: {ex.Message}");
                    }
                }

                // log error details
                if (config.VerboseErrors && valid.ValidationErrors.Count > 0)
                {
                    // todo - add the verbose errors
                }

                Console.WriteLine(JsonSerializer.Serialize(logDict, JsonOptions));
            }
        }
Exemple #22
0
        public MainPage()
        {
            this.InitializeComponent();

            PerfLog.Measure("App Load", () => LoadApplication(new XamFormsPerf.App()));
        }
Exemple #23
0
 public string TestsSummary()
 {
     return(PerfLog.Summary());
 }
Exemple #24
0
 public NSString TestsSummary(NSString arg)
 {
     return(new NSString(PerfLog.Summary()));
 }
        private async void TimerEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            int index = 0;

            // verify http client
            if (Client == null)
            {
                Console.WriteLine($"{ValidationTest.Now}\tError\tTimerState http client is null");
                return;
            }

            // exit if cancelled
            if (Token.IsCancellationRequested)
            {
                return;
            }

            // get a semaphore slot - rate limit the requests
            if (!loopController.WaitOne(10))
            {
                return;
            }

            // lock the state for updates
            lock (Lock)
            {
                index = Index;

                // increment
                Index++;

                // keep the index in range
                if (Index >= MaxIndex)
                {
                    Index = 0;
                }
            }

            // randomize request index
            if (Random != null)
            {
                index = Random.Next(0, MaxIndex);
            }

            Request req = RequestList[index];

            try
            {
                // Execute the request
                PerfLog p = await Test.ExecuteRequest(Client, Server, req).ConfigureAwait(false);

                lock (Lock)
                {
                    // increment
                    Count++;
                    Duration += p.Duration;
                }
            }
            catch (Exception ex)
            {
                // log and ignore any error
                Console.WriteLine($"{ValidationTest.Now}\tLodeRunnerException\t{ex.Message}");
            }

            // make sure to release the semaphore
            loopController.Release();
        }
Exemple #26
0
 async Task GoToTest(Type type)
 {
     PerfLog.MeasureStart(type.Name);
     await Navigation.PushAsync(Activator.CreateInstance(type, _automated) as Page, false);
 }