Exemplo n.º 1
0
 public BenchmarkReport(
     bool success,
     BenchmarkCase benchmarkCase,
     GenerateResult generateResult,
     BuildResult buildResult,
     IReadOnlyList <ExecuteResult> executeResults,
     IReadOnlyList <Metric> metrics)
 {
     Success         = success;
     BenchmarkCase   = benchmarkCase;
     GenerateResult  = generateResult;
     BuildResult     = buildResult;
     ExecuteResults  = executeResults ?? Array.Empty <ExecuteResult>();
     AllMeasurements = ExecuteResults.SelectMany((results, index) => results.Measurements).ToArray();
     GcStats         = ExecuteResults.Count > 0 ? executeResults[executeResults.Count - 1].GcStats : default;
     Metrics         = metrics?.ToDictionary(metric => metric.Descriptor.Id)
                       ?? (IReadOnlyDictionary <string, Metric>)ImmutableDictionary <string, Metric> .Empty;
 }
Exemplo n.º 2
0
 /// <summary>
 ///     创造一个新的执行结果
 /// </summary>
 /// <param name="state">执行结果的状态</param>
 /// <param name="resultObj">结果对象</param>
 /// <returns>返回创建后的执行结果对象</returns>
 public static IExecuteResult <T> Create(ExecuteResults state, T resultObj)
 {
     return(new ExecuteResult <T>(state, resultObj));
 }
Exemplo n.º 3
0
 /// <summary>
 ///     创造一个新的执行结果
 /// </summary>
 /// <param name="state">执行结果的状态</param>
 /// <param name="resultObj">结果对象</param>
 /// <returns>返回创建后的执行结果对象</returns>
 public static IExecuteResult Create(ExecuteResults state, object resultObj)
 {
     return(new ExecuteResult(state, resultObj));
 }
Exemplo n.º 4
0
 /// <summary>
 ///     执行结果
 /// </summary>
 /// <param name="state">执行结果的状态</param>
 /// <param name="resultObj">结果对象</param>
 /// <param name="error">错误信息 </param>
 public ExecuteResult(ExecuteResults state, T resultObj, string error = null)
 {
     _resultObj = resultObj;
     Error      = error;
     State      = state;
 }
Exemplo n.º 5
0
        private void ExecuteProcess(IProcessDetails pd, HandlerEventArgs hargs)
        {
            IProcess        process  = null;
            IExecuteResults execRes  = null;
            var             transId  = Guid.NewGuid();
            Stopwatch       durWatch = null;
            long?           duration = null;

            bool hasDuration = false;

            try
            {
                IArguments pargs = null;

                // if there are any constructors with 1
                var ctors = pd.ProcessType.GetConstructors()
                            .Where(c => c.GetParameters().Count() == 1);

                if (ctors.Any())
                {
                    if (hargs is DirWatcherEventArgs)
                    {
                        var wa = (DirWatcherEventArgs)hargs;
                        pargs = new WatcherArguments(new TieFileInfo(wa.FullePath), pd.Id, pd.Name, DateTime.Now,
                                                     hargs.TriggerId, hargs.TriggerName, transId);

                        process = (TieProcess <WatcherArguments>)Activator.CreateInstance(pd.ProcessType, pargs);
                    }
                    else
                    {
                        var sa = (CronSchedulerEventArgs)hargs;
                        pargs = new SchedulerArguments(sa.QuartzCronExpression, pd.Id, pd.Name, DateTime.Now,
                                                       hargs.TriggerId, hargs.TriggerName, transId);


                        process = (TieProcess <SchedulerArguments>)Activator.CreateInstance(pd.ProcessType, pargs);
                    }
                }
                else
                {
                    // check if default constructor is present
                    var dctor = pd.ProcessType.GetConstructor(Type.EmptyTypes);

                    if (dctor != null)
                    {
                        process = (IProcess)Activator.CreateInstance(pd.ProcessType);
                    }
                }

                if (process != null)
                {
                    this._activeProcesses.Add(process);

                    durWatch = Stopwatch.StartNew();

                    execRes = process.Execute();

                    duration = durWatch.ElapsedMilliseconds;
                    durWatch.Stop();

                    hasDuration = true;
                }
            }
            catch (Exception pex)
            {
                // log error
                if (execRes == null)
                {
                    execRes = new ExecuteResults(false, ExecutionState.Failed, transId);
                }

                execRes.Errors.Add(pex.ToString());
            }
            finally
            {
                if (!hasDuration)
                {
                    duration = durWatch?.ElapsedMilliseconds;
                }


                if (execRes == null)
                {// here for backwards compatibility
                    execRes = new ExecuteResults(true, ExecutionState.ProcessCompatExec, transId);
                }

                ProcessExecutionResults(execRes, pd);

                if (process != null)
                {
                    this._activeProcesses.TryTake(out process);
                    this._logger.LogMessage(new StatusMessage("tie", $"{this._activeProcesses.Count} active processes"), process.GetHashCode().ToString());

                    process.Dispose();
                    process = null;
                }
                else
                {
                    // log that process was null and no work was performed
                    // give hargs details
                }
            }
        }