internal void OptimizeSetter() { using (PerformanceStatistics.StartGlobalStopwatch(PerformanceCounter.AdaptersCompilation)) { if (m_Setter != null && !(PropertyInfo.DeclaringType.IsValueType)) { MethodInfo setterMethod = PropertyInfo.GetSetMethod(true); if (IsStatic) { var paramExp = Expression.Parameter(typeof(object), "dummy"); var paramValExp = Expression.Parameter(typeof(object), "val"); var castParamValExp = Expression.Convert(paramValExp, this.PropertyInfo.PropertyType); var callExpression = Expression.Call(setterMethod, castParamValExp); var lambda = Expression.Lambda <Action <object, object> >(callExpression, paramExp, paramValExp); Interlocked.Exchange(ref m_OptimizedSetter, lambda.Compile()); } else { var paramExp = Expression.Parameter(typeof(object), "obj"); var paramValExp = Expression.Parameter(typeof(object), "val"); var castParamExp = Expression.Convert(paramExp, this.PropertyInfo.DeclaringType); var castParamValExp = Expression.Convert(paramValExp, this.PropertyInfo.PropertyType); var callExpression = Expression.Call(castParamExp, setterMethod, castParamValExp); var lambda = Expression.Lambda <Action <object, object> >(callExpression, paramExp, paramValExp); Interlocked.Exchange(ref m_OptimizedSetter, lambda.Compile()); } } } }
internal void Optimize() { if (AccessMode == InteropAccessMode.Reflection) { return; } MethodInfo methodInfo = this.MethodInfo as MethodInfo; if (methodInfo == null) { return; } using (PerformanceStatistics.StartGlobalStopwatch(PerformanceCounter.AdaptersCompilation)) { var ep = Expression.Parameter(typeof(object[]), "pars"); var objinst = Expression.Parameter(typeof(object), "instance"); var inst = Expression.Convert(objinst, MethodInfo.DeclaringType); Expression[] args = new Expression[Parameters.Length]; for (int i = 0; i < Parameters.Length; i++) { if (Parameters[i].ParameterType.IsByRef) { throw new InternalErrorException("Out/Ref params cannot be precompiled."); } else { var x = Expression.ArrayIndex(ep, Expression.Constant(i)); args[i] = Expression.Convert(x, Parameters[i].ParameterType); } } Expression fn; if (IsStatic) { fn = Expression.Call(methodInfo, args); } else { fn = Expression.Call(inst, methodInfo, args); } if (this.m_IsAction) { var lambda = Expression.Lambda <Action <object, object[]> >(fn, objinst, ep); Interlocked.Exchange(ref m_OptimizedAction, lambda.Compile()); } else { var fnc = Expression.Convert(fn, typeof(object)); var lambda = Expression.Lambda <Func <object, object[], object> >(fnc, objinst, ep); Interlocked.Exchange(ref m_OptimizedFunc, lambda.Compile()); } } }
internal void OptimizeGetter() { using (PerformanceStatistics.StartGlobalStopwatch(PerformanceCounter.AdaptersCompilation)) { if (m_Getter != null) { if (IsStatic) { var paramExp = Expression.Parameter(typeof(object), "dummy"); var propAccess = Expression.Property(null, PropertyInfo); var castPropAccess = Expression.Convert(propAccess, typeof(object)); var lambda = Expression.Lambda <Func <object, object> >(castPropAccess, paramExp); Interlocked.Exchange(ref m_OptimizedGetter, lambda.Compile()); } else { var paramExp = Expression.Parameter(typeof(object), "obj"); var castParamExp = Expression.Convert(paramExp, this.PropertyInfo.DeclaringType); var propAccess = Expression.Property(castParamExp, PropertyInfo); var castPropAccess = Expression.Convert(propAccess, typeof(object)); var lambda = Expression.Lambda <Func <object, object> >(castPropAccess, paramExp); Interlocked.Exchange(ref m_OptimizedGetter, lambda.Compile()); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Script"/> class. /// </summary> /// <param name="coreModules">The core modules to be pre-registered in the default global table.</param> public Script(CoreModules coreModules) { Options = new ScriptOptions(DefaultOptions); PerformanceStats = new PerformanceStatistics(); Registry = new Table(this); m_ByteCode = new ByteCode(this); m_GlobalTable = new Table(this).RegisterCoreModules(coreModules); m_MainProcessor = new Processor(this, m_GlobalTable, m_ByteCode); }
/// <summary> /// Computes the Solution Performance Statistics /// </summary> /// <param name="solution">The solution from which the report is generated</param> /// <returns>The generated Performance Statistics from the Solution</returns> public SolutionPerformanceStatistics GetSolutionPerformanceStatistics(Solution solution) { var truckStatisticBySolution = new Dictionary <NodeRouteSolution, TruckPerformanceStatistics>(); var totalRouteStatisticsByTruckState = new Dictionary <TruckState, RouteStatistics>(); var totalPerformanceStatistics = new PerformanceStatistics(); var totalRouteStatistics = new RouteStatistics(); foreach (var routeSolution in solution.RouteSolutions) { // calculate truck performance statistics var truckStatistics = CalculateTruckPerformanceStatistics(routeSolution); truckStatisticBySolution[routeSolution] = truckStatistics; // calculate total route statistics by truck state foreach (var truckState in truckStatistics.RouteStatisticsByTruckState.Keys) { if (!totalRouteStatisticsByTruckState.ContainsKey(truckState)) { totalRouteStatisticsByTruckState[truckState] = new RouteStatistics(); } totalRouteStatisticsByTruckState[truckState] += truckStatistics.RouteStatisticsByTruckState[truckState]; } // sum up performance & route stats totalPerformanceStatistics += truckStatistics.PerformanceStatistics; totalRouteStatistics += truckStatistics.RouteStatistics; } double solutionCount = solution.RouteSolutions.Count; var result = new SolutionPerformanceStatistics { TruckStatistics = truckStatisticBySolution, TotalRouteStatisticsByTruckState = totalRouteStatisticsByTruckState, TotalRouteStatistics = totalRouteStatistics, NumberOfBackhauls = totalPerformanceStatistics.NumberOfBackhauls, AverageNumberOfBackhauls = totalPerformanceStatistics.NumberOfBackhauls / solutionCount, NumberOfLoadmatches = totalPerformanceStatistics.NumberOfLoadmatches, AverageNumberOfLoadmatches = totalPerformanceStatistics.NumberOfLoadmatches / solutionCount, NumberOfJobs = totalPerformanceStatistics.NumberOfJobs, AverageNumberOfJobs = totalPerformanceStatistics.NumberOfJobs / solutionCount, AverageDriverDutyHourUtilization = totalPerformanceStatistics.DriverDutyHourUtilization / solutionCount, AverageDriverDrivingUtilization = totalPerformanceStatistics.DriverDrivingUtilization / solutionCount, DrivingTimePercentage = totalRouteStatistics.TotalTravelTime.TotalHours / totalRouteStatistics.TotalTime.TotalHours, WaitingTimePercentage = totalRouteStatistics.TotalIdleTime.TotalHours / totalRouteStatistics.TotalTime.TotalHours }; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="Script"/> class. /// </summary> /// <param name="coreModules">The core modules to be pre-registered in the default global table.</param> public Script(CoreModules coreModules) { Options = new ScriptOptions(DefaultOptions); PerformanceStats = new PerformanceStatistics(); Registry = new Table(this); m_ByteCode = new ByteCode(this); m_MainProcessor = new Processor(this, m_GlobalTable, m_ByteCode); m_GlobalTable = new Table(this).RegisterCoreModules(coreModules); foreach (var t in TypeDescriptorRegistry.RegisteredTypes) { Type valType = t.Value.Type; if (valType.GetTypeInfo().Assembly.FullName != typeof(Script).GetTypeInfo().Assembly.FullName) { // m_GlobalTable.RegisterModuleType(t.Value.Type); if (t.Value is StandardUserDataDescriptor) { StandardUserDataDescriptor desc = (StandardUserDataDescriptor)t.Value; foreach (var member in desc.Members) { if (member.Value is MethodMemberDescriptor) { MethodMemberDescriptor methDesc = (MethodMemberDescriptor)member.Value; if (methDesc.IsConstructor) { m_GlobalTable.Set(methDesc.Name, methDesc.GetCallbackAsDynValue(this)); } } else if (member.Value is OverloadedMethodMemberDescriptor) { OverloadedMethodMemberDescriptor methDesc = (OverloadedMethodMemberDescriptor)member.Value; foreach (var overloadDesc in methDesc.m_Overloads) { if (overloadDesc is MethodMemberDescriptor) { MethodMemberDescriptor actualDesc = (MethodMemberDescriptor)overloadDesc; if (actualDesc.IsConstructor) { //m_GlobalTable.Set(desc.FriendlyName, actualDesc.GetCallbackAsDynValue(this)); m_GlobalTable.Set(desc.FriendlyName, DynValue.NewCallback(methDesc.GetCallbackFunction(this))); break; } } } } } } } } }
/// <summary> /// Computes the performance statistics for a given route solution /// </summary> /// <param name="routeSolution">The solution from which the report is generated</param> /// <returns>the statistics generated from the route</returns> private PerformanceStatistics CalculatePerformanceStatistics(NodeRouteSolution routeSolution) { var result = new PerformanceStatistics() { NumberOfJobs = routeSolution.JobCount, DriverDutyHourUtilization = routeSolution.RouteStatistics.TotalTime.TotalHours / routeSolution.DriverNode.Driver.AvailableDutyTime.TotalHours, DriverDrivingUtilization = routeSolution.RouteStatistics.TotalTravelTime.TotalHours / routeSolution.DriverNode.Driver.AvailableDrivingTime.TotalHours, DrivingTimePercentage = routeSolution.RouteStatistics.TotalTravelTime.TotalHours / routeSolution.RouteStatistics.TotalTime.TotalHours, WaitingTimePercentage = routeSolution.RouteStatistics.TotalIdleTime.TotalHours / routeSolution.RouteStatistics.TotalTime.TotalHours, NumberOfBackhauls = CalculateNumberOfBackhauls(routeSolution), NumberOfLoadmatches = CalculateNumberOfLoadMatches(routeSolution) }; return(result); }
internal override void OptimizeGetter(FieldInfo fi) { #if !ONLY_AOT using (PerformanceStatistics.StartGlobalStopwatch(PerformanceCounter.AdaptersCompilation)) { // We want something that behaves like this: //lambda = (Script sc, TObj obj) => ClrToScriptConversions.ObjectToDynValue(sc, fi.GetValue(obj)); Expression <Func <Script, TObj, DynValue> > lambda; if (IsStatic) { var param1 = Expression.Parameter(typeof(Script), "script"); var param2 = Expression.Parameter(typeof(object), "container"); var fiGetValue = Expression.Field(null, fi); var objToDynValueCall = Expression.Call(typeof(ClrToScriptConversions).GetMethod("GenericToDynValue", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(fi.FieldType), param1, fiGetValue); lambda = Expression.Lambda <Func <Script, TObj, DynValue> >(objToDynValueCall, param1, param2); } else { if (fi.DeclaringType.IsValueType) { var param1 = Expression.Parameter(typeof(Script), "script"); var param2 = Expression.Parameter(fi.DeclaringType, "container"); var fiGetValue = Expression.Field(param2, fi); var objToDynValueCall = Expression.Call(typeof(ClrToScriptConversions).GetMethod("GenericToDynValue", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(fi.FieldType), param1, fiGetValue); lambda = Expression.Lambda <Func <Script, TObj, DynValue> >(objToDynValueCall, param1, param2); } else { var param1 = Expression.Parameter(typeof(Script), "script"); var param2 = Expression.Parameter(fi.DeclaringType, "container"); var fiGetValue = Expression.Field(param2, fi); var nullCheck = Expression.NotEqual(param2, Expression.Constant(null, typeof(object))); var objToDynValueCall = Expression.Call(typeof(ClrToScriptConversions).GetMethod("GenericToDynValue", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(fi.FieldType), param1, fiGetValue); var nilDynValueCall = Expression.Invoke((Expression <Func <DynValue> >)(() => DynValue.Nil)); var ifNotNull = Expression.Condition(nullCheck, objToDynValueCall, nilDynValueCall); lambda = Expression.Lambda <Func <Script, TObj, DynValue> >(ifNotNull, param1, param2); } } Interlocked.Exchange(ref m_OptimizedGetter, lambda.Compile()); } #endif }
public async Task <ActionResult> Index() { var viewModel = new ViewModel(); var performance = new PerformanceStatistics(); viewModel.CpuUsage = await performance.GetCurrentCpuUsage(); viewModel.MemoryAvailable = await performance.GetAvailableRAM(); viewModel.TotalMemory = performance.GetTotalRAM(); var disk = new DiskStatistics(); viewModel.FreeArray = disk.FreeSpace; viewModel.TotalArray = disk.TotalSpace; viewModel.UsedArray = disk.UsedSpace; viewModel.MovieNames = disk.MovieTitles; viewModel.TVShowNames = disk.TvShowTitles; //viewModel.NumberOfPhotos = disk.NumberOfPhotos; return(View(viewModel)); }
internal void Optimize() { using (PerformanceStatistics.StartGlobalStopwatch(PerformanceCounter.AdaptersCompilation)) { var ep = Expression.Parameter(typeof(object[]), "pars"); var objinst = Expression.Parameter(typeof(object), "instance"); var inst = Expression.Convert(objinst, MethodInfo.DeclaringType); Expression[] args = new Expression[m_Arguments.Length]; for (int i = 0; i < m_Arguments.Length; i++) { var x = Expression.ArrayIndex(ep, Expression.Constant(i)); args[i] = Expression.Convert(x, m_Arguments[i]); } Expression fn; if (IsStatic) { fn = Expression.Call(MethodInfo, args); } else { fn = Expression.Call(inst, MethodInfo, args); } if (MethodInfo.ReturnType == typeof(void)) { var lambda = Expression.Lambda <Action <object, object[]> >(fn, objinst, ep); Interlocked.Exchange(ref m_OptimizedAction, lambda.Compile()); } else { var fnc = Expression.Convert(fn, typeof(object)); var lambda = Expression.Lambda <Func <object, object[], object> >(fnc, objinst, ep); Interlocked.Exchange(ref m_OptimizedFunc, lambda.Compile()); } } }
public GameBase() { /* * SpriteBatch & GraphicsDeviceManager */ GraphicsDeviceManager = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; /* * Engine */ // Initialize game components _performanceStatistics = new PerformanceStatistics(this); // Initialize game state manager StateManager = new GameStateManager(this); // Initialize states GameLobby = new LobbyState(this); GameWorld = new WorldState(this); // Add game components Components.Add(_performanceStatistics); Components.Add(StateManager); StateManager.ChangeState((LobbyState)GameLobby); // Change state to game lobby //StateManager.ChangeState((WorldState)GameWorld); // Enable unlimited FPS, mouse visible and set title IsFixedTimeStep = false; IsMouseVisible = true; Window.Title = "Mario Royale"; }
public async Task <JsonResult> CurrentRamAvailable() { var performance = new PerformanceStatistics(); return(Json(await performance.GetAvailableRAM())); }
public async Task <JsonResult> CurrentCpuPercentage() { var performance = new PerformanceStatistics(); return(Json(await performance.GetCurrentCpuUsage())); }
private void btnProfileStats_Click(object sender, System.EventArgs e) { PerformanceStatistics stats = this.rapi.CFPerformanceMonitor.GetCurrentStatistics(); MessageBox.Show("Total stat count: " + stats.Count.ToString()); }