public IChromosome[] MutateChromosomeByNodeFlipping(IChromosome[] chromosomesByEdgeCount, IChromosome[] chromosomesByConnectedEdge, IMatrix matrix, int maxDiffBetweenNode) { var numberOfTimes = (int)chromosomesByEdgeCount.Length / 3.0; var random = new Random(); using (_profiler.Step(nameof(MutateChromosomeByNodeFlipping))) { for (var i = 0; i < numberOfTimes; i++) { var(left, rigth) = RandomNumberGeneratorUtils.GenerateTwoRandomNumbers(random, 0, chromosomesByEdgeCount.Length); chromosomesByEdgeCount[left] = _chromosomeService.FlipNodeOnChromosoe(chromosomesByEdgeCount[left], maxDiffBetweenNode, matrix); chromosomesByConnectedEdge[rigth] = _chromosomeService.FlipNodeOnChromosoe(chromosomesByConnectedEdge[rigth], maxDiffBetweenNode, matrix); } } var result = new List <IChromosome>(); foreach (var chromosome in chromosomesByEdgeCount) { result.Add(chromosome.DeepCopy()); } foreach (var chromosome in chromosomesByConnectedEdge) { result.Add(chromosome.DeepCopy()); } return(result.ToArray()); }
public void ServerTimingFormat() { var mp = new MiniProfiler("Test", Options); using (mp.Step("Main")) { using (mp.Step("Sub Step 1")) { mp.Head.AddCustomTiming("A", new CustomTiming() { DurationMilliseconds = 5 }); } using (mp.Step("Sub Step 2")) { mp.Head.AddCustomTiming("A", new CustomTiming() { DurationMilliseconds = 10.1m }); mp.Head.AddCustomTiming("B", new CustomTiming() { DurationMilliseconds = 8.2345m }); } } mp.Stop(); mp.DurationMilliseconds = 5m + 10.1m + 8.2345m; // Since we're synthetic here, need to set it var st = mp.GetServerTimingHeader(); Assert.Equal(@"A;desc=""A"";dur=15.1,B;desc=""B"";dur=8.23,total;desc=""Total"";dur=23.33", st); }
public ActionResult About() { using (profiler.Step("peak Profile About")) { ViewBag.Message = "Your application description page."; } return(View()); }
/// <summary> /// list转换pageList /// </summary> /// <typeparam name="T"></typeparam> /// <param name="allList">需要分页的数据</param> /// <returns></returns> private PageList <T> ConvertPageList <T>(List <T> allList, int pageIndex, int pageSize) { using (MiniProfilerLog.Step("转化为列表page方法 ConvertPageList")) { pageIndex = pageIndex <= 0 ? 1 : pageIndex; pageSize = pageSize <= 0 ? 10 : pageSize; int skip = (pageIndex - 1) * pageSize; var list = allList?.Skip(skip).Take(pageSize).ToList(); return(new PageList <T>(list, pageIndex, pageSize, allList == null ? 0 : allList.LongCount())); } }
// // GET: /Import/ public ActionResult Index() { // Get last 5 product hashes var productHashes = context.Imports .Where(i => i.type == ImportCategories.Products) .OrderByDescending(i => i.CreatedAt) .Take(5) .Select(i => i.contentHash); // Get the last 5 sales hashes var salesHashes = context.Imports .Where(i => i.type == ImportCategories.Sales) .OrderByDescending(i => i.CreatedAt) .Take(5) .Select(i => i.contentHash); // Get the date of the most recent products import var lastProductsImportDate = context.Imports .Where(i => i.type == ImportCategories.Products) .OrderByDescending(i => i.CreatedAt) .Select(i => i.CreatedAt) .FirstOrDefault(); // Get the date of the most recent sales import var lastSalesImportDate = context.Imports .Where(i => i.type == ImportCategories.Sales) .OrderByDescending(i => i.CreatedAt) .Select(i => i.CreatedAt) .FirstOrDefault(); // Send this data to the view for client-side validations using (profiler.Step("Store validation data in ViewBag")) { using (profiler.Step("Put hashes in ViewBag")) { ViewBag.hashes = productHashes.Concat(salesHashes).ToArray(); } using (profiler.Step("Put last products import date in ViewBag")) { ViewBag.lastProductsImportDate = lastProductsImportDate.ToString("s"); } using (profiler.Step("Put last sales import date in ViewBag")) { ViewBag.lastSalesImportDate = lastSalesImportDate.ToString("s"); } } return(View(new ImportViewModel())); }
/// <summary> /// Returns a profiler for <paramref name="url"/>. Only child steps will take any time, /// e.g. when <paramref name="childDepth"/> is 0, the resulting <see cref="MiniProfiler.DurationMilliseconds"/> will be zero. /// </summary> /// <param name="childDepth">number of levels of child steps underneath result's <see cref="MiniProfiler.Root"/></param> /// <param name="stepsEachTakeMilliseconds">Amount of time each step will "do work for" in each step</param> /// <returns>the mini profiler</returns> public static MiniProfiler GetProfiler( string url = DefaultRequestUrl, int childDepth = 0, int stepsEachTakeMilliseconds = StepTimeMilliseconds) { MiniProfiler result = null; Action step = null; var curDepth = 0; // recursively add child steps step = () => { if (curDepth++ < childDepth) { using (result.Step("Depth " + curDepth)) { IncrementStopwatch(stepsEachTakeMilliseconds); step(); } } }; using (GetRequest(url, startAndStopProfiler: false)) { result = MiniProfiler.Start(); step(); MiniProfiler.Stop(); } return(result); }
public IList <GraphEdges> GraphEdges(IMatrix matrix) { var nodeNeighbors = _graphConsistentService.GetNodeNeighbors(matrix); var result = new List <GraphEdges>(); using (_profiler.Step(nameof(GraphEdges))) { for (var i = 0; i < nodeNeighbors.Count; i++) { for (var j = 0; j < nodeNeighbors[i].Neighbors.Length; j++) { result.Add(new GraphEdges { From = nodeNeighbors[i].Id.ToString(), To = nodeNeighbors[i].Neighbors[j].NeighborNumber.ToString(), Label = nodeNeighbors[i].Neighbors[j].EdgeValue.ToString(), Font = new Font { Align = "top" } }); result.Add(new GraphEdges { From = nodeNeighbors[i].Neighbors[j].NeighborNumber.ToString(), To = nodeNeighbors[i].Id.ToString(), }); } } } return(result); }
public PageView <PhototechnicsViewModel.Summary> GetPhotorentTechnics(RouteEntityViewModel.Summary route, PageRequest <RentCalendar> request) { PageView <PhototechnicsViewModel.Summary> page; using (MiniProfiler.Step("Loading Context.Phototechnics")) { page = _context.Value.RentCalendars .Include(x => x.Phototechnics) .Include(x => x.Photorent) .Include(x => x.Phototechnics.Raiting) .Include(x => x.Phototechnics.Category) .Include(x => x.Phototechnics.Brand) .OrderBy(x => x.Phototechnics.Raiting.Total) .ToPage(request) .AsPageView <PhototechnicsViewModel.Summary>(); } foreach (var element in page.Elements) { if (route.WhiteLabel) { element.Shortcut = _urlBuilder.GetRouteForObject(new RouteObject { CategorySlug = element.CategorySlug, Domain = route.Domain, RouteShortcut = route.Shortcut, Shortcut = element.Shortcut, WhiteLabel = route.WhiteLabel }); } } return(page); }
/// <summary> /// Returns a listing of blog posts /// </summary> /// <param name="posts">Posts to be displayed</param> /// <param name="count">Number of posts being displayed</param> /// <param name="page">Page number of the current page</param> /// <param name="viewName">Name of the view to render</param> /// <param name="viewModel">View model to pass to the view</param> /// <returns>Post listing</returns> private ActionResult Listing(IEnumerable <PostModel> posts, int count, int page, string viewName = null, ListingViewModel viewModel = null) { if (viewName == null) { viewName = Views.Index; } if (viewModel == null) { viewModel = new ListingViewModel(); } var pages = (int)Math.Ceiling((double)count / ITEMS_PER_PAGE); if (page > pages) { return(HttpNotFound(string.Format("Requested page number ({0}) is greater than page count ({1})", page, count))); } using (_profiler.Step("Building post ViewModels")) { viewModel.Posts = posts.Select(post => new PostViewModel { Post = post, ShortUrl = ShortUrl(post), SocialNetworks = GetSocialNetworks(post) }); } viewModel.TotalCount = count; viewModel.Page = page; viewModel.TotalPages = pages; return(View(viewName, viewModel)); }
protected void Application_BeginRequest(object sender, EventArgs e) { Current.Context.Response.BufferOutput = true; // MvcMiniProfiler stuff: MiniProfiler profiler = null; // might want to decide here (or maybe inside the action) whether you want // to profile this request - for example, using an "IsSystemAdmin" flag against // the user, or similar; this could also all be done in action filters, but this // is simple and practical; just return null for most users. For our test, we'll // profile only for local requests (seems reasonable) //if (Request.IsLocal) //{ // profiler = MvcMiniProfiler.MiniProfiler.Start(); //} #if DEBUG profiler = MvcMiniProfiler.MiniProfiler.Start(); #endif using (profiler.Step("Application_BeginRequest")) { // you can start profiling your code immediately } }
public PageView <MasterclassViewModel.Summary> Where(PageRequest <Masterclass> request = null) { if (request == null) { request = new PageRequest <Masterclass>(); } PageView <MasterclassViewModel.Summary> page; using (MiniProfiler.Step("Load Context.Masterclass")) { var startdate = DateTime.Today.AddDays(-2); page = Context.Masterclasses .Where(x => x.Start > startdate) .OfType <Masterclass>() .OrderBy(x => x.Pro) .ThenBy(x => x.Verified) .ThenByDescending(x => x.Raiting.Total) .ToPage(request) .AsPageView <MasterclassViewModel.Summary>(); } return(page); }
protected override void Append(LoggingEvent loggingEvent) { //Sample output of what Nhibernate outputs and this code tries to "parse" //Building an IDbCommand object for the SqlString: INSERT INTO "RecipientList" (Name, Description) VALUES (?, ?); select last_insert_rowid() //Building an IDbCommand object for the SqlString: SELECT this_.Id as Id4_0_, this_.Name as Name4_0_, this_.Description as Descript3_4_0_ FROM "RecipientList" this_ if (loggingEvent.LoggerName.Equals("NHibernate.AdoNet.AbstractBatcher")) { string msg = loggingEvent.MessageObject.ToString(); if (msg.StartsWith(_buildingAnIdbcommandObjectForTheSqlstring)) { MiniProfiler profiler = MiniProfiler.Current; timer.Value = profiler.Step(logText(msg)); } //Sample of NHibernate ouptut when closing //2011-06-30 10:23:23,515 [9] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed IDbCommand, open IDbCommands: 0 if (msg.StartsWith("Closed IDbCommand")) { if (timer.Value != null) { timer.Value.Dispose(); timer.Value = null; } } } }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (_profiler == null || !_profiler.IsActive) { return(_command.ExecuteReader(behavior)); } DbDataReader result = null; using (_profiler.Step(EF_STRING, EFProviderUtilities.GetFormattedSqlCommand(_command.CommandText, _command.Parameters))) { result = _command.ExecuteReader(behavior); result = new ProfiledDbDataReader(result, _connection, _profiler); } return(result); }
/// <summary> /// Does a Step with the location of caller as the label. /// </summary> public static IDisposable StepHere( this MiniProfiler profiler, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { return(profiler?.Step($"{memberName} - {Path.GetFileName(sourceFilePath)}:{sourceLineNumber}")); }
public MiniProfiler calInside(int idx) { profiler.Inline(() => Slowpoke.Sleep(2, 5, 20), "inside inline"); using (profiler.Step("inside step")) Slowpoke.Sleep(2, 4, 10); // mp.Stop(); return(profiler); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step("OnActionExecuting")) { base.OnActionExecuting(filterContext); } }
protected async override Task OnInitializedAsync() { _profiler = MiniProfiler.StartNew(nameof(OnInitializedAsync)); using (_profiler.Step(nameof(StartAsync))) { await StartAsync(); } Console.WriteLine(_profiler.RenderPlainText()); }
public IQueryable <T> All <T>(Expression <Func <T, bool> > expression) where T : IMongoEntity { MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step(string.Format("select table {0} query All {1}", typeof(T).Name, expression))) { return(All <T>().Where(expression)); } }
public IQueryable <T> All <T>() where T : IMongoEntity { MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step(string.Format("select table {0} query {1}", typeof(T).Name, "all"))) { return(Get(typeof(T).Name, _db.GetCollection(typeof(T).Name).AsQueryable <T>)); } }
public T GetOne <T>(Expression <Func <T, bool> > expression) where T : IMongoEntity { MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step(string.Format("select table {0} query getone {1}", typeof(T).Name, expression))) { return(All <T>().Where(expression).SingleOrDefault()); } }
public async Task <string> Ping() { MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step("Ping")) { return(await PingService.Ping()); } }
private void HandleBeginTrace(TraceRecord record) { MiniProfiler profiler = MiniProfiler.Current; if (profiler != null) { IDisposable step = profiler.Step(record.Message); this.bag.TryAdd(record, step); } }
public async Task <ActionResult> List() { MiniProfiler profiler = MiniProfiler.Current; IEnumerable <ActivityLogModel> logs; using (profiler.Step("Get activity list")) { using (profiler.Step("Get all activities")) { logs = await ActivityService.GetActivityLogs(); } using (profiler.Step("Get all label types")) { ViewBag.TypeLabels = ActivityService.GetActivityTypeLabels(); } } return(View(logs)); }
public ActionResult Index() { using (mp.Step("Set page title")) { ViewBag.Title = "Home Page"; } using (mp.Step("Doing complex stuff")) { using (mp.Step("Step A")) { Thread.Sleep(100); } using (mp.Step("Step B")) { Thread.Sleep(250); } } using (var db = GetOpenConnection()) { var contacts = db.GetList <Contact>().ToList(); return(View(contacts)); } }
protected void AddRecursiveChildren(MiniProfiler profiler, int maxDepth, int stepMs, int curDepth = 0) { if (curDepth++ < maxDepth) { using (profiler.Step("Depth " + curDepth)) { profiler.Increment(stepMs); AddRecursiveChildren(profiler, maxDepth, stepMs, curDepth); } } }
/// <summary> /// Does a Step with the location of caller as the label. /// </summary> public static IDisposable StepHere( this MiniProfiler profiler, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { if (profiler == null) { return(null); } return(profiler.Step(string.Format("{0} - {1}:{2}", memberName, Path.GetFileName(sourceFilePath), sourceLineNumber))); }
private void UpsertRouteHit(ActionDescriptor actionDesc, MiniProfiler profiler) { var routeName = actionDesc.ControllerDescriptor.ControllerName + "/" + actionDesc.ActionName; using (var conn = GetConnection(profiler)) { var param = new { routeName = routeName }; using (profiler.Step("Insert RouteHits")) { conn.Execute("insert or ignore into RouteHits (RouteName, HitCount) values (@routeName, 0)", param); } using (profiler.Step("Update RouteHits")) { // let's put some whitespace in this query to demonstrate formatting conn.Execute( @"update RouteHits set HitCount = HitCount + 1 where RouteName = @routeName", param); } } }
private MiniProfiler GetMiniProfiler() { var mp = new MiniProfiler("Test"); using (mp.Step("Foo")) { using (mp.CustomTiming("Hey", "There")) { // heyyyyyyyyy } } return(mp); }
/// <summary> /// 新增加Application_BeginRequest方法,添加MiniProfiler启动方法 /// </summary> protected void Application_BeginRequest() { MiniProfiler profiler = null; if (Request.IsLocal) { profiler = MiniProfiler.StartNew(); } using (profiler.Step("Application_BeginRequest")) { //Todo } }
public async Task <ActionResult> Index() { ViewBag.ActivePage = ActivePageName; DashboardViewModel model = new DashboardViewModel(); MiniProfiler profiler = MiniProfiler.Current; using (profiler.Step("Get events")) { model.RecentActivity = await EventLogService.GetEvents(10); } return(View(model)); }