public TimeSpan GetTotal(DateTime start, DateTime end) { TimeSpan ts = new TimeSpan(0); foreach (Fluent fluent in laps) { if (fluent.Start > end) { continue; } if (fluent.Stopped && fluent.End < start) { continue; } DateTime effectiveStart = (start > fluent.Start) ? start : fluent.Start; DateTime effectiveEnd = (end < fluent.End) ? end : fluent.End; if (!fluent.Stopped) { effectiveEnd = DateTime.Now; } if (effectiveStart > effectiveEnd) { continue; } ts = ts.Add(effectiveEnd.Subtract(effectiveStart)); } return(ts); }
public TimeSpan GetTotal() { TimeSpan ts = new TimeSpan(0); foreach (Fluent fluent in laps) { ts = ts.Add(fluent.GetTimeSpan()); } return(ts); }
private TimeSpan(System.TimeSpan baseValue, int microseconds, int nanoseconds) { // const string method = ".ctor"; // If microsecond value is too large update the milliseconds (same with nanoseconds). // This is the behaviour of System.TimeSpan. Store microseconds as Int64 in // case the addition of nanoseconds pushes it over Int32.MaxValue. long carry = System.Math.DivRem(nanoseconds, DateTimeHelper.Microseconds2Nanoseconds, out nanoseconds); long totalMicroseconds = microseconds + carry; carry = System.Math.DivRem(totalMicroseconds, (long)DateTimeHelper.Milliseconds2Microseconds, out totalMicroseconds); microseconds = (int)totalMicroseconds; // We're back in Int32 range // Add carried over milliseconds to the base TimeSpan value // try // { baseValue = (carry == 0 ? baseValue : baseValue.Add( new System.TimeSpan(0, 0, 0, 0, (int)carry))); // } // catch (OverflowException) // { // throw new ParameterOutOfRangeException(typeof(TimeSpan), method, // "value", baseValue.ToString() + " + " + carry.ToString() + " ms"); // } // Make sure all parts (base TimeSpan, microseconds, nanoseconds) have the same sign int sign = System.Math.Sign(baseValue.TotalMilliseconds); if (sign == 0) { sign = System.Math.Sign(microseconds); } if (sign != 0) { if (nanoseconds != 0 && System.Math.Sign(nanoseconds) != sign) { nanoseconds += DateTimeHelper.Microseconds2Nanoseconds * sign; microseconds -= sign; } if (microseconds != 0 && System.Math.Sign(microseconds) != sign) { microseconds += DateTimeHelper.Milliseconds2Microseconds * sign; baseValue = baseValue.Subtract(new System.TimeSpan(0, 0, 0, 0, sign)); } } m_base = baseValue; m_microseconds = microseconds; m_nanoseconds = nanoseconds; }
DumpProfiles() { var profileHeader = "Task"; var minutesHeader = "Minutes"; var secondsHeader = "Seconds"; var millisecondsHeader = "Milliseconds"; int maxNameLength = profileHeader.Length; int maxMinuteLength = minutesHeader.Length; int maxSecondLength = secondsHeader.Length; int maxMillisecondLength = millisecondsHeader.Length; foreach (var profile in Profiles) { int nameLength = profile.Profile.ToString().Length; if (nameLength > maxNameLength) { maxNameLength = nameLength; } int minuteLength = profile.Elapsed.Minutes.ToString().Length; if (minuteLength > maxMinuteLength) { maxMinuteLength = minuteLength; } int secondLength = profile.Elapsed.Seconds.ToString().Length; if (secondLength > maxSecondLength) { maxSecondLength = secondLength; } int millisecondLength = profile.Elapsed.Milliseconds.ToString().Length; if (millisecondLength > maxMillisecondLength) { maxMillisecondLength = millisecondLength; } } var header = System.String.Format("{0}{1} | {2}{3} | {4}{5} | {6}{7}", profileHeader, new string(' ', maxNameLength - profileHeader.Length), minutesHeader, new string(' ', maxMinuteLength - minutesHeader.Length), secondsHeader, new string(' ', maxSecondLength - secondsHeader.Length), millisecondsHeader, new string(' ', maxMillisecondLength - millisecondsHeader.Length)); var sectionRule = new string('=', header.Length); var profileRule = new string('-', header.Length); Log.Info("\nTask timing"); Log.Info(sectionRule); Log.Info(header); Log.Info(sectionRule); var cumulativeTime = new System.TimeSpan(); foreach (var profile in Profiles) { var requiresProfileRule = true; var elapsedTime = profile.Elapsed; if (ETimingProfiles.TimedTotal != profile.Profile) { cumulativeTime = cumulativeTime.Add(elapsedTime); } var minuteString = elapsedTime.Minutes > 0 ? elapsedTime.Minutes.ToString() : string.Empty; var secondString = elapsedTime.Seconds > 0 ? elapsedTime.Seconds.ToString() : string.Empty; var millisecondString = elapsedTime.Milliseconds > 0 ? elapsedTime.Milliseconds.ToString() : string.Empty; if (ETimingProfiles.TimedTotal == profile.Profile) { Log.Info(sectionRule); Log.Info(sectionRule); var cumulativeString = "CumulativeTotal"; var cumulativeMinutesString = cumulativeTime.Minutes > 0 ? cumulativeTime.Minutes.ToString() : string.Empty; var cumulativeSecondsString = cumulativeTime.Seconds > 0 ? cumulativeTime.Seconds.ToString() : string.Empty; var cumulativeMillisecondsString = cumulativeTime.Milliseconds > 0 ? cumulativeTime.Milliseconds.ToString() : string.Empty; Log.Info("{0}{1} | {2}{3} | {4}{5} | {6}{7}", cumulativeString, new string(' ', maxNameLength - cumulativeString.Length), new string(' ', maxMinuteLength - cumulativeMinutesString.Length), cumulativeMinutesString, new string(' ', maxSecondLength - cumulativeSecondsString.Length), cumulativeSecondsString, new string(' ', maxMillisecondLength - cumulativeMillisecondsString.Length), cumulativeMillisecondsString); Log.Info(sectionRule); requiresProfileRule = false; } else if (ETimingProfiles.GraphExecution == profile.Profile) { requiresProfileRule = false; } Log.Info("{0}{1} | {2}{3} | {4}{5} | {6}{7}", profile.Profile.ToString(), new string(' ', maxNameLength - profile.Profile.ToString().Length), new string(' ', maxMinuteLength - minuteString.Length), minuteString, new string(' ', maxSecondLength - secondString.Length), secondString, new string(' ', maxMillisecondLength - millisecondString.Length), millisecondString); if (requiresProfileRule) { Log.Info(profileRule); } } Log.Info(sectionRule); }
DumpProfiles() { var additionalDetails = false; var profileHeader = "Profile"; var minutesHeader = "Minutes"; var secondsHeader = "Seconds"; var millisecondsHeader = "Milliseconds"; var startTimeHeader = "Start"; var stopTimeHeader = "Stop"; int maxNameLength = profileHeader.Length; int maxMinuteLength = minutesHeader.Length; int maxSecondLength = secondsHeader.Length; int maxMillisecondLength = millisecondsHeader.Length; int maxTimeLength = 9; foreach (var profile in Profiles) { int nameLength = profile.Profile.ToString().Length; if (nameLength > maxNameLength) { maxNameLength = nameLength; } int minuteLength = profile.Elapsed.Minutes.ToString().Length; if (minuteLength > maxMinuteLength) { maxMinuteLength = minuteLength; } int secondLength = profile.Elapsed.Seconds.ToString().Length; if (secondLength > maxSecondLength) { maxSecondLength = secondLength; } int millisecondLength = profile.Elapsed.Milliseconds.ToString().Length; if (millisecondLength > maxMillisecondLength) { maxMillisecondLength = millisecondLength; } } var header = System.String.Format("{0}{1} | {2}{3} | {4}{5} | {6}{7} | {8}{9} | {10}{11}", profileHeader, new string(' ', maxNameLength - profileHeader.Length), minutesHeader, new string(' ', maxMinuteLength - minutesHeader.Length), secondsHeader, new string(' ', maxSecondLength - secondsHeader.Length), millisecondsHeader, new string(' ', maxMillisecondLength - millisecondsHeader.Length), new string(' ', maxTimeLength - startTimeHeader.Length), startTimeHeader, new string(' ', maxTimeLength - stopTimeHeader.Length), stopTimeHeader); var horizontalRule = new string('-', header.Length); Log.Info("\nTask timing"); Log.Info(horizontalRule); Log.Info(header); Log.Info(horizontalRule); var cumulativeTime = new System.TimeSpan(); foreach (var profile in Profiles) { var elapsedTime = (null != profile) ? profile.Elapsed : new System.TimeSpan(0); if (ETimingProfiles.TimedTotal != profile.Profile) { cumulativeTime = cumulativeTime.Add(elapsedTime); } string diffString = null; if (additionalDetails && (ETimingProfiles.TimedTotal != profile.Profile)) { var diff = profile.Start - Profiles.First().Stop; diffString = diff.Milliseconds.ToString(); } var minuteString = elapsedTime.Minutes.ToString(); var secondString = elapsedTime.Seconds.ToString(); var millisecondString = elapsedTime.Milliseconds.ToString(); var startTimeString = (null != profile) ? profile.Start.ToString(TimeProfile.DateTimeFormat) : "0"; var stopTimeString = (null != profile) ? profile.Stop.ToString(TimeProfile.DateTimeFormat) : "0"; if (ETimingProfiles.TimedTotal == profile.Profile) { Log.Info(horizontalRule); var cumulativeString = "CumulativeTotal"; var cumulativeMinutesString = cumulativeTime.Minutes.ToString(); var cumulativeSecondsString = cumulativeTime.Seconds.ToString(); var cumulativeMillisecondsString = cumulativeTime.Milliseconds.ToString(); Log.Info("{0}{1} | {2}{3} | {4}{5} | {6}{7}", cumulativeString, new string(' ', maxNameLength - cumulativeString.Length), new string(' ', maxMinuteLength - cumulativeMinutesString.Length), cumulativeMinutesString, new string(' ', maxSecondLength - cumulativeSecondsString.Length), cumulativeSecondsString, new string(' ', maxMillisecondLength - cumulativeMillisecondsString.Length), cumulativeMillisecondsString); Log.Info(horizontalRule); } Log.Info("{0}{1} | {2}{3} | {4}{5} | {6}{7} | {8}{9} | {10}{11} {12}", profile.Profile.ToString(), new string(' ', maxNameLength - profile.Profile.ToString().Length), new string(' ', maxMinuteLength - minuteString.Length), minuteString, new string(' ', maxSecondLength - secondString.Length), secondString, new string(' ', maxMillisecondLength - millisecondString.Length), millisecondString, new string(' ', maxTimeLength - startTimeString.Length), startTimeString, new string(' ', maxTimeLength - stopTimeString.Length), stopTimeString, diffString); } Log.Info(horizontalRule); }
public static TimeSpan Parse(string i) { string[] dt = i.Split(new char[] { 'P', 'T' }); string d = ""; string t = ""; if (dt.Length == 3) { d = dt[1]; t = dt[2]; } else { if (i.IndexOf('P') != -1) d = dt[1]; else t = dt[1]; } System.TimeSpan ts = new System.TimeSpan(); if (d.IndexOf('Y') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('Y'))); d = d.Substring(d.IndexOf('Y') + 1); ts.Add(new System.TimeSpan(365 * val, 0, 0, 0)); } if (d.IndexOf('M') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('M'))); d = d.Substring(d.IndexOf('M') + 1); ts.Add(new System.TimeSpan(30 * val, 0, 0, 0)); } if (d.IndexOf('D') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('D'))); d = d.Substring(d.IndexOf('D') + 1); ts.Add(new System.TimeSpan(val, 0, 0, 0)); } if (t.IndexOf('H') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('H'))); t = t.Substring(t.IndexOf('H') + 1); ts.Add(new System.TimeSpan(0, val, 0, 0)); } if (t.IndexOf('M') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('M'))); t = t.Substring(t.IndexOf('M') + 1); ts.Add(new System.TimeSpan(0, 0, val, 0)); } if (t.IndexOf('S') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('S'))); t = t.Substring(t.IndexOf('S') + 1); ts.Add(new System.TimeSpan(0, 0, 0, val)); } return new TimeSpan(ts); }
static public TimeSpan Parse(string i) { string[] dt = i.Split(new char[] { 'P', 'T' }); string d = ""; string t = ""; if (dt.Length == 3) { d = dt[1]; t = dt[2]; } else { if (i.IndexOf('P') != -1) { d = dt[1]; } else { t = dt[1]; } } System.TimeSpan ts = new System.TimeSpan(); if (d.IndexOf('Y') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('Y'))); d = d.Substring(d.IndexOf('Y') + 1); ts.Add(new System.TimeSpan(365 * val, 0, 0, 0)); } if (d.IndexOf('M') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('M'))); d = d.Substring(d.IndexOf('M') + 1); ts.Add(new System.TimeSpan(30 * val, 0, 0, 0)); } if (d.IndexOf('D') != -1) { int val = System.Convert.ToInt16(d.Substring(0, d.IndexOf('D'))); d = d.Substring(d.IndexOf('D') + 1); ts.Add(new System.TimeSpan(val, 0, 0, 0)); } if (t.IndexOf('H') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('H'))); t = t.Substring(t.IndexOf('H') + 1); ts.Add(new System.TimeSpan(0, val, 0, 0)); } if (t.IndexOf('M') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('M'))); t = t.Substring(t.IndexOf('M') + 1); ts.Add(new System.TimeSpan(0, 0, val, 0)); } if (t.IndexOf('S') != -1) { int val = System.Convert.ToInt16(t.Substring(0, t.IndexOf('S'))); t = t.Substring(t.IndexOf('S') + 1); ts.Add(new System.TimeSpan(0, 0, 0, val)); } return(new TimeSpan(ts)); }
public void RefreshList() { listTimers.BeginUpdate(); int lastSelectedIndex = listTimers.SelectedIndex; listTimers.Items.Clear(); this.listTimerValues.Clear(); foreach (Timer timer in timers.GetTimers()) { try { string duration = GetTimeSpanString(GetTimeSpan(timer)); string text = timer.Name + duration; if (timer.Started) { text = "* " + text + " Started"; } listTimers.Items.Add(text); listTimerValues.Add(timer); ClearMessage(); } catch { ShowMessage("Incorrect format string"); } } if (timers.GetTimerGroups().Count > 0) { //Add spacer listTimers.Items.Add(""); listTimerValues.Add(null); } foreach (TimerGroup group in timers.GetTimerGroups()) { try { TimeSpan ts = new TimeSpan(0); bool started = false; foreach (Timer timer in group.Timers) { ts = ts.Add(GetTimeSpan(timer)); if (timer.Started) { started = true; } } string duration = GetTimeSpanString(ts) + GetRateString(ts, group); string text = group.Name + duration; if (started) { text = "* " + text + " Started"; } listTimers.Items.Add(text); listTimerValues.Add(group); ClearMessage(); } catch { ShowMessage("Incorrect format string"); } } listTimers.SelectedIndex = lastSelectedIndex; listTimers.EndUpdate(); }
public TimeSpan Add(TimeSpan ts) { return(new TimeSpan(m_base.Add(ts.m_base), m_microseconds + ts.m_microseconds, m_nanoseconds + ts.m_nanoseconds)); }