public void Enqueue(IAnalyzable item, AnalysisPriority priority) { ThrowIfDisposed(); var iPri = (int)priority; if (iPri < 0 || iPri > _queue.Length) { throw new ArgumentException("priority"); } lock (_queueLock) { // see if we have the item in the queue anywhere... for (var i = 0; i < _queue.Length; i++) { if (_queue[i].Remove(item)) { Interlocked.Decrement(ref _analysisPending); var oldPri = (AnalysisPriority)i; if (oldPri > priority) { // if it was at a higher priority then our current // priority go ahead and raise the new entry to our // old priority priority = oldPri; } break; } } // enqueue the work item Interlocked.Increment(ref _analysisPending); if (priority == AnalysisPriority.High) { // always try and process high pri items immediately _queue[iPri].Insert(0, item); } else { _queue[iPri].Add(item); } try { _workEvent.Set(); } catch (IOException) { } catch (ObjectDisposedException) { // Queue was closed while we were running } } }
private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority, CancellationToken cancellationToken) { if (item is IGroupableAnalysisProjectEntry groupable) { var added = _enqueuedGroups.Add(groupable.AnalysisGroup); if (added) { Enqueue(new GroupAnalysis(groupable.AnalysisGroup, this), priority); } groupable.Analyze(cancellationToken, true); } else { item.Analyze(cancellationToken); } }
public void Enqueue(IAnalyzable item, AnalysisPriority priority) { int iPri = (int)priority; if (iPri < 0 || iPri > _queue.Length) { throw new ArgumentException("priority"); } lock (_queueLock) { // see if we have the item in the queue anywhere... for (int i = 0; i < _queue.Length; i++) { if (_queue[i].Remove(item)) { AnalysisPriority oldPri = (AnalysisPriority)i; if (oldPri > priority) { // if it was at a higher priority then our current // priority go ahead and raise the new entry to our // old priority priority = oldPri; } break; } } // enqueue the work item if (priority == AnalysisPriority.High) { // always try and process high pri items immediately _queue[iPri].Insert(0, item); } else { _queue[iPri].Add(item); } _event.Set(); } }
public void Enqueue(IAnalyzable item, AnalysisPriority priority) { int iPri = (int)priority; if (iPri < 0 || iPri > _queue.Length) { throw new ArgumentException("priority"); } lock (_queueLock) { // see if we have the item in the queue anywhere... for (int i = 0; i < _queue.Length; i++) { if (_queue[i].Remove(item)) { Interlocked.Decrement(ref _analysisPending); AnalysisPriority oldPri = (AnalysisPriority)i; if (oldPri > priority) { // if it was at a higher priority then our current // priority go ahead and raise the new entry to our // old priority priority = oldPri; } break; } } // enqueue the work item Interlocked.Increment(ref _analysisPending); if (priority == AnalysisPriority.High) { // always try and process high pri items immediately _queue[iPri].Insert(0, item); } else { _queue[iPri].Add(item); } try { _workEvent.Set(); } catch (ObjectDisposedException) { // Queue was closed while we were running } } }
private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority, CancellationToken cancellationToken) { if (item is IGroupableAnalysisProjectEntry groupable) { var added = _enqueuedGroups.Add(groupable.AnalysisGroup); if (added) { try { Enqueue(new GroupAnalysis(groupable.AnalysisGroup, this), priority); } catch (ObjectDisposedException) when(_ppc.IsDisposed) { return; } } groupable.Analyze(cancellationToken, true); } else { item.Analyze(cancellationToken); } }
/// <summary> /// Среднее время нахождения заявки в системе. /// </summary> public static float SummaryAverageClientTime(IAnalyzable diagram) => AverageClientQueueWaitingTime(diagram) + AverageClientServiceTime(diagram);
/// <summary> /// Среднее время обслуживания заявки. /// 0, если нет обсуженных заявок. /// </summary> public static float AverageClientServiceTime(IAnalyzable diagram) => diagram.ServedClientCount == 0 ? 0 : (float)diagram.SummaryServiceTime / diagram.ServedClientCount;
/// <summary> /// Общее количество заявок. /// </summary> public static float SummaryClientCount(IAnalyzable diagram) => diagram.SummaryClientCount;
/// <summary> /// Количество отказанных заявок. /// </summary> public static float LostClientCount(IAnalyzable diagram) => diagram.LostClientCount;
/// <summary> /// Среднее время ожидания заявки в очереди. /// 0, если нет заявок, ожидавших в очереди. /// </summary> public static float AverageClientQueueWaitingTime(IAnalyzable diagram) => diagram.QueuedClientCount == 0 ? 0 : (float)(diagram.QueueBusyTimes.Sum() / diagram.QueuedClientCount);
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously /// <summary> /// Initialize with analyzable, you should call base method when override this method /// </summary> /// <param name="analyzable">Analyzable</param> /// <returns>Task object</returns> public async virtual Task InitWithAnalyzableAsync(IAnalyzable analyzable) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { _analyzable = analyzable; // Implement your own logic here }
public bool TryGetBackendFor(IAnalyzable peripheral, out IAnalyzableBackend backend) { return(map.TryGetValue(peripheral, out backend)); }
/// <summary> /// Вероятность занятости только <paramref name="channelCount"/> каналов. /// 0, если <paramref name="channelCount"/> больше кол-ва каналов; /// </summary> public static float ChannelBusyProbality(IAnalyzable diagram, int channelCount) => (channelCount > diagram.ChannelCount) ? 0 : (float)(diagram.ChannelBusyTimes[channelCount] / diagram.SystemWorkTime);
public void Enqueue(IAnalyzable item, AnalysisPriority priority) { Enqueue(item, ct => HandleAnalyzable(item, priority, ct), priority); }
/// <summary> /// Вероятность отказа. /// </summary> public static float RefuseProbality(IAnalyzable diagram) => (float)diagram.LostClientCount / diagram.SummaryClientCount;
/// <summary> /// Пропускная способность системы. /// </summary> public static float SystemThroughput(IAnalyzable diagram) => (float)(diagram.ServedClientCount / diagram.SystemWorkTime);
/// <summary> /// Вероятность обслуживания. /// </summary> public static float ServedProbality(IAnalyzable diagram) => (float)diagram.ServedClientCount / diagram.SummaryClientCount;
/// <summary> /// Количество показателей. /// </summary> public static int TotalMetricsCount(IAnalyzable diagram) => 9 + diagram.ChannelCount * 2 + diagram.QueueCapacity;
/// <summary> /// Время работы системы. /// </summary> public static float SystemWorkTime(IAnalyzable diagram) => (float)diagram.SystemWorkTime;
/// <summary> /// Среднее количество заявок, находящихся в системе. /// </summary> public static float AverageClientCount(IAnalyzable diagram) => (float)diagram.AverageClientCount;
internal void StartTestCoverage(IAnalyzable project) { project.RunTestCoverage(); }
public static string MakeReport(IAnalyzable diagram, IEnumerable <Metric> clientMetrics, IEnumerable <Metric> metrics) => "Показатели системы:\r\n" + string.Join("\r\n", clientMetrics.Select(metric => string.Format(" {0}: {1} {2}", metric.Name, metric.Formula(diagram), metric.Units))) + "\r\n\r\nАнализ диаграммы:\r\n" + string.Join("\r\n", metrics.Select(metric => string.Format(" {0}: {1} {2}", metric.Name, metric.Formula(diagram), metric.Units)));
/// <summary> /// Вероятность того, что в очереди будет только <paramref name="clientCount"/> заявок. /// 0, если <paramref name="clientCount"/> больше кол-ва каналов; /// </summary> public static float QueueBusyProbality(IAnalyzable diagram, int clientCount) => (clientCount > diagram.QueueCapacity) ? 0 : (float)(diagram.QueueBusyTimes[clientCount - 1] / diagram.SystemWorkTime);
internal void AddProject(IAnalyzable project) { m_ProjectList.Add(project); }
/// <summary> /// Среднее количество заявок в очереди. /// </summary> public static float AverageClientCountInQueue(IAnalyzable diagram) => (float)diagram.QueueBusyTimes.Select((value, index) => (index + 1) * (value / diagram.SystemWorkTime)).Sum();
/// <summary> /// Среднее количество занятых каналов. /// </summary> public static float AverageBusyChannelCount(IAnalyzable diagram) => (float)diagram.ChannelBusyTimes.Select((value, index) => index * (value / diagram.SystemWorkTime)).Sum();
/// <summary> /// Количество обслуженных заявок. /// </summary> public static float ServedClientCount(IAnalyzable diagram) => diagram.ServedClientCount;
/// <summary> /// Вероятность простоя хотя бы <paramref name="channelCount"/> каналов. /// 0, если <paramref name="channelCount"/> больше кол-ва каналов; /// </summary> public static float ChannelIdleProbality(IAnalyzable diagram, int channelCount) => (channelCount > diagram.ChannelCount) ? 0 : (float)(diagram.ChannelBusyTimes.Reverse().Skip(channelCount).Sum() / diagram.SystemWorkTime);
internal void StartAnalyzer(IAnalyzable project) { project.AnalyzeProject(); }