/// <summary>
 ///     Adjust Settings to match information from proto descriptor.
 /// </summary>
 /// <returns></returns>
 public static Settings DefaultAdjustFunction(Settings settings, DevDescriptor devDescriptor)
 {
     settings.AggregationStrategy.AnnotationEnumSize.Clear();
     settings.AggregationStrategy.AnnotationEnumSize.AddRange(devDescriptor.annotationEnumSizes);
     settings.AggregationStrategy.MaxInstrumentationKeys = settings.Histograms.Count;
     settings.LevelAnnotationIndex   = devDescriptor.sceneAnnotationIndex;
     settings.LoadingAnnotationIndex = devDescriptor.loadingAnnotationIndex;
     settings.MergeFrom(k_SettingsToMerge);
     return(settings);
 }
        /// <summary>
        ///     Save settings to a file.
        /// </summary>
        /// <param name="settings">settings to save</param>
        /// <param name="presaveAdjust">Function to automatically change settings before saving them</param>
        public static void SaveSettings(Settings settings, DevDescriptor devDescriptor, AdjustSettings presaveAdjust)
        {
            settings = presaveAdjust(settings, devDescriptor);
            Directory.CreateDirectory(Path.GetDirectoryName(Paths.devSettingsPath));
            using (var output = File.Create(Paths.devSettingsPath))
            {
                settings.WriteTo(output);
            }

            AssetDatabase.Refresh();
        }
Пример #3
0
        static void Init()
        {
            Debug.Log("Android Performance Tuner Initializer");

            setupConfig   = FileUtil.LoadSetupConfig();
            devDescriptor = CreateDescriptor();

            // When a new package is imported in Unity 2018, EditorBuildSettings.scenes are not updated yet when
            // Initializer() is called, thus the .proto file does not reflect possible changes in the scenes.
            // This callback creates the .proto file when the package has finished importing and the
            // EditorBuildSettings are up to date.
#if UNITY_2018
            AssetDatabase.importPackageCompleted += (packageName) =>
            {
                CreateProtoFile(devDescriptor);
            };
#endif

            enumInfoHelper = new EnumInfoHelper(devDescriptor.fileDescriptor);
            protoFile      = CreateProtoFile(devDescriptor);

            CreateAsmdefFile();

            projectData = new ProjectData();
            projectData.LoadFromStreamingAssets(devDescriptor);

            EditorBuildSettings.sceneListChanged += () =>
            {
                Debug.Log("Android Performance Tuner SceneListChanged");
                UpdateSceneEnum();
            };

            if (!FidelityBuilder.builder.valid)
            {
                initMessage = "Fidelity message is not generated yet or your project is still compiling. " +
                              "If this message persists, try to re-import the plugin and generated assets." +
                              "\n[macOS] Check if protoc compiler can be opened. " +
                              "In the Finder locate protoc binary in AndroidPerformanceTuner/Editor/Protoc, " +
                              "control-click the binary, choose Open and then click Open. ";
                Debug.Log(initMessage);
                valid = false;
                return;
            }

            UpdateFidelityMessages();
            CheckForLoadingStateInAnnotation();

            // TODO(kseniia): Check for possible inconsistencies in the data, set to false if any found
            // TODO(kseniia): or remove "valid" if all problems could be fixed in-place
            valid = true;
        }
        /// <summary>
        ///     Load settings from from a file.
        /// </summary>
        /// <param name="defaultSettings">Save and return defaultSettings if there are no saved settings.</param>
        /// <returns>Return loaded or default settings.</returns>
        public static Settings LoadSettings(Settings defaultSettings, DevDescriptor devDescriptor,
                                            AdjustSettings presaveAdjust)
        {
            if (!File.Exists(Paths.devSettingsPath))
            {
                SaveSettings(defaultSettings, devDescriptor, presaveAdjust);
                return(defaultSettings);
            }

            using (var input = File.OpenRead(Paths.devSettingsPath))
            {
                var settings = Settings.Parser.ParseFrom(input);
                return(settings);
            }
        }
Пример #5
0
        static Initializer()
        {
            Debug.Log("Android Performance Tuner Initializer");

            setupConfig = FileUtil.LoadSetupConfig();

            devDescriptor = CreateDescriptor();

            protoFile = CreateProtoFile(devDescriptor);

            CreateAsmdefFile();

            projectData = new ProjectData();
            projectData.LoadFromStreamingAssets(devDescriptor);

            enumInfoHelper = new EnumInfoHelper(devDescriptor.fileDescriptor);

            EditorBuildSettings.sceneListChanged += () =>
            {
                Debug.Log("Android Performance Tuner SceneListChanged");
                UpdateSceneEnum();
            };

            if (!FidelityBuilder.builder.valid)
            {
                initMessage = "Fidelity message is not generated yet or your project is still compiling. " +
                              "If this message persists, try to re-import the plugin and generated assets." +
                              "\n[macOS] Check if protoc compiler can be opened. " +
                              "In the Finder locate protoc binary in AndroidPerformanceTuner/Editor/Protoc, " +
                              "control-click the binary, choose Open and then click Open. ";
                Debug.Log(initMessage);
                valid = false;
                return;
            }

            UpdateFidelityMessages();

            // TODO(kseniia): Check for possible inconsistencies in the data, set to false if any found
            // TODO(kseniia): or remove "valid" if all problems could be fixed in-place
            valid = true;
        }
        static Proto.FileInfo CreateProtoFile(DevDescriptor devDescriptor)
        {
            var protoFile = new Proto.FileInfo(devDescriptor.fileDescriptor);

            // Always add scene and loading state enum.
            protoFile.AddEnum(EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes));
            protoFile.AddEnum(DefaultMessages.loadingStateEnum);

            protoFile.onUpdate += () =>
            {
                Action onFail = null;
                if (File.Exists(Paths.devProtoPath))
                {
                    var previousText = File.ReadAllText(Paths.devProtoPath);
                    onFail = () => { File.WriteAllText(Paths.devProtoPath, previousText); };
                }

                Directory.CreateDirectory(Path.GetDirectoryName(Paths.devProtoPath));
                File.WriteAllText(Paths.devProtoPath, protoFile.ToProtoString());
                if (!ProtocCompiler.GenerateProtoAndDesc() && onFail != null)
                {
                    onFail();
                }
                else
                {
                    AssetDatabase.Refresh();
                    areFidelityMessagesDirty = true;
                }
            };

            // If files do not exist yet, call OnUpdate to generate them (.proto, .descriptor and .cs).
            if (!File.Exists(Paths.devProtoPath) ||
                !File.Exists(Paths.devDescriptorPath) ||
                !FidelityBuilder.builder.valid)
            {
                protoFile.onUpdate();
            }

            return(protoFile);
        }
        static DevDescriptor CreateDescriptor()
        {
            if (File.Exists(Paths.devDescriptorPath))
            {
                var bytes           = File.ReadAllBytes(Paths.devDescriptorPath);
                var savedDescriptor = new DevDescriptor(bytes);
                if (savedDescriptor.Build())
                {
                    // Descriptor is successfully loaded from saved .descriptor file
                    return(savedDescriptor);
                }

                Debug.LogErrorFormat(
                    "Android Performance Tuner: Proto definition from {0} could not be loaded, it will be replaced by default proto",
                    Paths.devDescriptorPath);
            }

            // TODO(kseniia): Save .descriptor, .cs, etc.
            var defaultDescriptor = new DevDescriptor(DefaultMessages.serializedDefaultProto);

            defaultDescriptor.Build();
            return(defaultDescriptor);
        }
Пример #8
0
        public void LoadFromStreamingAssets(DevDescriptor descriptor)
        {
            m_DevDescriptor = descriptor;
            m_Settings      = FileUtil.LoadSettings(SettingsUtil.defaultSettings, m_DevDescriptor,
                                                    SettingsUtil.DefaultAdjustFunction);

            if (AreSettingsDirty())
            {
                FileUtil.SaveSettings(m_Settings, descriptor, SettingsUtil.DefaultAdjustFunction);
            }

            try
            {
                m_DefaultFidelityParametersIndex =
                    FileUtil.GetFidelityMessageIndex(m_Settings.DefaultFidelityParametersFilename);
            }
            catch (ArgumentException)
            {
                defaultFidelityParametersIndex = 1;
            }

            messages = FileUtil.LoadAllFidelityMessages();
            RefreshTrends();
        }
 public FidelityParametersEditor(ProjectData projectData, DevDescriptor devDescriptor)
 {
     m_ProjectData   = projectData;
     m_DevDescriptor = devDescriptor;
 }