Example #1
0
        public static void SendAdaptiveStartupEvent(Provider.AdaptivePerformanceSubsystem subsystem)
        {
#if UNITY_ANALYTICS
            if (s_AdaptivePerformanceEvent == null)
            {
                s_AdaptivePerformanceEvent = new AdaptivePerformanceAnalyticsEvent();
            }

            s_AdaptivePerformanceEvent.initialized    = subsystem != null ? subsystem.initialized : false;
            s_AdaptivePerformanceEvent.activeProvider = subsystem != null ? subsystem.SubsystemDescriptor.id : "NoSubsystemLoaded";

            s_AdaptivePerformanceEvent.UpdateGeneralEventData();
            var providerData = s_AdaptivePerformanceEvent.providerData;
            if (subsystem != null)
            {
                for (var i = 0; i < providerData.Length; ++i)
                {
                    if (providerData[i].id == subsystem.SubsystemDescriptor.id)
                    {
                        providerData[i].version = subsystem.Version.ToString();
                        providerData[i].enabled = subsystem.initialized;
                    }
                }
            }
            s_AdaptivePerformanceEvent.UpdateFeatureData();

            Send(EventName.AdaptivePerformance, s_AdaptivePerformanceEvent);
#endif
        }
        private bool InitializeSubsystem(Provider.AdaptivePerformanceSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            subsystem.Start();

            if (subsystem.initialized)
            {
                m_Subsystem = subsystem;

                APLog.Debug("version={0}", m_Subsystem.Version);

                return(true);
            }
            else
            {
                subsystem.Destroy();

                return(false);
            }
        }
        public void Start()
        {
            APLog.enabled            = StartupSettings.Logging;
            LoggingFrequencyInFrames = StartupSettings.StatsLoggingFrequencyInFrames;
            if (!StartupSettings.Enable)
            {
                return;
            }

            if (InitializeSubsystem(StartupSettings.PreferredSubsystem))
            {
                m_Subsystem = StartupSettings.PreferredSubsystem;
            }
            else
            {
                System.Collections.Generic.List <Provider.AdaptivePerformanceSubsystemDescriptor> perfDescriptors = Provider.AdaptivePerformanceSubsystemRegistry.GetRegisteredDescriptors();
                if (perfDescriptors.Count == 0)
                {
                    APLog.Debug("No Subsystems found and initialized.");
                }
                foreach (var perfDesc in perfDescriptors)
                {
                    var subsystem = perfDesc.Create();
                    if (InitializeSubsystem(subsystem))
                    {
                        m_Subsystem = subsystem;
                        break;
                    }
                }
            }

            if (m_Subsystem != null)
            {
                m_DevicePerfControl = new DevicePerformanceControlImpl(m_Subsystem.PerformanceLevelControl);
                m_AutoPerformanceLevelController = new AutoPerformanceLevelController(m_DevicePerfControl, PerformanceStatus, ThermalStatus);

                m_AppLifecycle = m_Subsystem.ApplicationLifecycle;

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuFrameTime))
                {
                    m_CpuFrameTimeProvider = new CpuTimeProvider();
                    StartCoroutine(InvokeEndOfFrame());
                }

                m_TemperatureTrend = new TemperatureTrend(m_Subsystem.Capabilities.HasFlag(Provider.Feature.TemperatureTrend));

                if (m_RequestedCpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedCpuLevel = m_DevicePerfControl.MaxCpuPerformanceLevel;
                }

                if (m_RequestedGpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedGpuLevel = m_DevicePerfControl.MaxGpuPerformanceLevel;
                }

                if (m_Subsystem.PerformanceLevelControl == null)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.System;
                }
                else if (AutomaticPerformanceControl)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Automatic;
                }
                else
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Manual;
                }

                ThermalEvent += (ThermalMetrics thermalMetrics) => LogThermalEvent(thermalMetrics);
                PerformanceBottleneckChangeEvent += (PerformanceBottleneckChangeEventArgs ev) => LogBottleneckEvent(ev);
                PerformanceLevelChangeEvent      += (PerformanceLevelChangeEventArgs ev) => LogPerformanceLevelEvent(ev);

                UpdateSubsystem();
            }
        }
Example #4
0
        public AutoPerformanceLevelController(IDevicePerformanceControl perfControl, IPerformanceStatus perfStat, IThermalStatus thermalStat, Provider.AdaptivePerformanceSubsystem subsystem)
        {
            UpdateInterval                   = 5.0f;
            TargetFrameTime                  = -1.0f;
            AllowedCpuActiveTimeRatio        = 0.8f;
            AllowedGpuActiveTimeRatio        = 0.9f;
            GpuLevelBounceAvoidanceThreshold = 10.0f;
            CpuLevelBounceAvoidanceThreshold = 10.0f;
            MinTargetFrameRateHitTime        = 10.0f;
            MaxTemperatureLevel              = 0.9f;

            m_PerfStats    = perfStat;
            m_PerfControl  = perfControl;
            m_ThermalStats = thermalStat;

            if (subsystem.Version == m_Version)
            {
                m_MinCPULevel = 1;
            }


            perfStat.PerformanceBottleneckChangeEvent += (PerformanceBottleneckChangeEventArgs ev) => OnBottleneckChange(ev);
            AdaptivePerformanceAnalytics.RegisterFeature(m_featureName, m_Enabled);
        }
        public void Awake()
        {
            APLog.enabled = true;
            if (AdaptivePerformanceGeneralSettings.Instance == null)
            {
                APLog.Debug("No Provider was configured for use. Make sure you added at least one Provider in the Adaptive Performance Settings.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            if (!AdaptivePerformanceGeneralSettings.Instance.InitManagerOnStart)
            {
                APLog.Debug("Adaptive Performance is disabled via Settings.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            var activeLoader = AdaptivePerformanceGeneralSettings.Instance.Manager.ActiveLoaderAs <AdaptivePerformanceLoader>();

            if (activeLoader == null)
            {
                APLog.Debug("No Active Loader was found. Make sure to select your loader in the Adaptive Performance Settings for this platform.");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            m_Settings = activeLoader.GetSettings();
            if (m_Settings == null)
            {
                APLog.Debug("No Settings available. Did the Post Process Buildstep fail?");
                AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                return;
            }

            AutomaticPerformanceControl = m_Settings.automaticPerformanceMode;
            LoggingFrequencyInFrames    = m_Settings.statsLoggingFrequencyInFrames;
            APLog.enabled = m_Settings.logging;

            if (m_Subsystem == null)
            {
                var subsystem = (Provider.AdaptivePerformanceSubsystem)activeLoader.GetDefaultSubsystem();

                if (subsystem != null)
                {
                    if (subsystem.initialized)
                    {
                        m_Subsystem = subsystem;
                        APLog.Debug("Subsystem version={0}", m_Subsystem.Version);
                    }
                    else
                    {
                        subsystem.Destroy();
                        APLog.Debug("Subsystem not initialized.");
                        AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
                        return;
                    }
                }
            }

            if (m_Subsystem != null)
            {
                m_UseProviderOverallFrameTime    = m_Subsystem.Capabilities.HasFlag(Provider.Feature.OverallFrameTime);
                m_DevicePerfControl              = new DevicePerformanceControlImpl(m_Subsystem.PerformanceLevelControl);
                m_AutoPerformanceLevelController = new AutoPerformanceLevelController(m_DevicePerfControl, PerformanceStatus, ThermalStatus);

                m_AppLifecycle = m_Subsystem.ApplicationLifecycle;

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuFrameTime))
                {
                    m_CpuFrameTimeProvider = new CpuTimeProvider();
                    StartCoroutine(InvokeEndOfFrame());
                }

                if (!m_Subsystem.Capabilities.HasFlag(Provider.Feature.GpuFrameTime))
                {
                    m_GpuFrameTimeProvider = new GpuTimeProvider();
                }

                m_TemperatureTrend = new TemperatureTrend(m_Subsystem.Capabilities.HasFlag(Provider.Feature.TemperatureTrend));

                // Request maximum performance by default
                if (m_RequestedCpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedCpuLevel = m_DevicePerfControl.MaxCpuPerformanceLevel;
                }
                if (m_RequestedGpuLevel == Constants.UnknownPerformanceLevel)
                {
                    m_RequestedGpuLevel = m_DevicePerfControl.MaxGpuPerformanceLevel;
                }

                // Override to get maximum performance by default in 'auto' mode
                m_NewUserPerformanceLevelRequest = true;

                if (m_Subsystem.PerformanceLevelControl == null)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.System;
                }
                else if (AutomaticPerformanceControl)
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Automatic;
                }
                else
                {
                    m_DevicePerfControl.PerformanceControlMode = PerformanceControlMode.Manual;
                }

                ThermalEvent += (ThermalMetrics thermalMetrics) => LogThermalEvent(thermalMetrics);
                PerformanceBottleneckChangeEvent += (PerformanceBottleneckChangeEventArgs ev) => LogBottleneckEvent(ev);
                PerformanceLevelChangeEvent      += (PerformanceLevelChangeEventArgs ev) => LogPerformanceLevelEvent(ev);

                if (m_Subsystem.Capabilities.HasFlag(Provider.Feature.CpuPerformanceBoost))
                {
                    PerformanceBoostChangeEvent += (PerformanceBoostChangeEventArgs ev) => LogBoostEvent(ev);
                }

                Indexer = new AdaptivePerformanceIndexer(ref m_Settings);

                UpdateSubsystem();
            }
            AdaptivePerformanceAnalytics.SendAdaptiveStartupEvent(m_Subsystem);
        }