示例#1
0
    // The actual window code goes here
    void OnGUI()
    {
        if (odhCalloutBackgroundStyle == null)
        {
            odhCalloutBackgroundStyle = new GUIStyle(EditorStyles.helpBox);
            var odhCalloutBackgroundStyleTex = new Texture2D(1, 1);
            odhCalloutBackgroundStyleTex.SetPixel(0, 0, new Color(0.9f, 0.8f, 0.2f, 0.2f));
            odhCalloutBackgroundStyleTex.Apply();
            odhCalloutBackgroundStyle.normal.background = odhCalloutBackgroundStyleTex;
        }

        if (odhCalloutTextStyle == null)
        {
            odhCalloutTextStyle          = new GUIStyle(EditorStyles.label);
            odhCalloutTextStyle.richText = true;
            odhCalloutTextStyle.wordWrap = true;
        }

        // ODH Callout Section
        GUILayout.BeginHorizontal(odhCalloutBackgroundStyle);
        var     script      = MonoScript.FromScriptableObject(this);
        string  assetPath   = AssetDatabase.GetAssetPath(script);
        string  editorPath  = Path.GetDirectoryName(assetPath);
        string  odhIconPath = Path.Combine(editorPath, "Textures\\odh_icon.png");
        Texture ODHIcon     = (Texture)EditorGUIUtility.Load(odhIconPath);

        GUILayout.Box(ODHIcon, GUILayout.Width(60.0f), GUILayout.Height(60.0f));

        GUILayout.BeginVertical();

        EditorGUILayout.LabelField("<b>This tool is deprecated.</b> Oculus recommends profiling builds through the Metrics section of "
                                   + "<b>Oculus Developer Hub</b>, a desktop companion tool that streamlines the Quest development workflow.",
                                   odhCalloutTextStyle);
        GUIContent ODHLabel = new GUIContent("Download Oculus Developer Hub");

#if UNITY_2021_1_OR_NEWER
        if (EditorGUILayout.LinkButton(ODHLabel))
#else
        if (GUILayout.Button(ODHLabel, GUILayout.ExpandWidth(false)))
#endif
        {
#if UNITY_EDITOR_WIN
            Application.OpenURL("https://developer.oculus.com/downloads/package/oculus-developer-hub-win/?source=unity");
#elif UNITY_EDITOR_OSX
            Application.OpenURL("https://developer.oculus.com/downloads/package/oculus-developer-hub-mac/?source=unity");
#endif
        }
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.Space(15.0f);

        showAndroidOptions = EditorGUILayout.Foldout(showAndroidOptions, "Android Tools");

        if (showAndroidOptions)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Android SDK root path: ", androidSdkRootPath);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start Server"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.StartServer(null);
                    EditorUtility.DisplayDialog("ADB StartServer", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Kill Server"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.KillServer(null);
                    EditorUtility.DisplayDialog("ADB KillServer", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Forward Port"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.ForwardPort(remoteListeningPort, null);
                    EditorUtility.DisplayDialog("ADB ForwardPort", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                    OVRPlugin.SendEvent("device_metrics_profiler", (exitCode == 0 ? "adb_forward_success" : "adb_forward_failure"));
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Release Port"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.ReleasePort(remoteListeningPort, null);
                    EditorUtility.DisplayDialog("ADB ReleasePort", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        GUILayout.BeginHorizontal();
        remoteListeningPort = EditorGUILayout.DelayedIntField("Remote Port", remoteListeningPort);

        if (tcpClient.connectionState == OVRNetwork.OVRNetworkTcpClient.ConnectionState.Disconnected)
        {
            if (GUILayout.Button("Connect"))
            {
                ConnectPerfMetricsTcpServer();
                pauseReceiveMetrics = false;
                OVRPlugin.SendEvent("device_metrics_profiler", "connect");
            }
        }
        else
        {
            if (tcpClient.connectionState == OVRNetwork.OVRNetworkTcpClient.ConnectionState.Connecting)
            {
                if (GUILayout.Button("Connecting ... Click again to Cancel"))
                {
                    DisconnectPerfMetricsTcpServer();
                    OVRPlugin.SendEvent("device_metrics_profiler", "cancel");
                }
            }
            else
            {
                if (GUILayout.Button("Disconnect"))
                {
                    DisconnectPerfMetricsTcpServer();
                    OVRPlugin.SendEvent("device_metrics_profiler", "disconnect");
                }

                if (GUILayout.Button(pauseReceiveMetrics ? "Continue" : "Pause"))
                {
                    pauseReceiveMetrics = !pauseReceiveMetrics;
                }
            }
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        lock (receivedMetricsList)
        {
            PresentIntProperty("Frame Count", "frameCount");
            PresentIntProperty("Dropped Frame Count", "compositorDroppedFrameCount");

            float?avgFrameTime = GetAveragePerfValueFloat("deltaFrameTime");
            if (avgFrameTime.HasValue)
            {
                float fps = 1.0f / avgFrameTime.Value;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("FPS", GUILayout.Width(labelWidth));
                EditorGUILayout.LabelField(string.Format("{0:F1}", fps));
                EditorGUILayout.EndHorizontal();
            }

            int?  deviceCpuClockLevel          = GetLatestPerfValueInt("deviceCpuClockLevel");
            int?  deviceGpuClockLevel          = GetLatestPerfValueInt("deviceGpuClockLevel");
            float?deviceCpuClockFrequencyInMHz = GetLatestPerfValueFloat("deviceCpuClockFrequencyInMHz");
            float?deviceGpuClockFrequencyInMHz = GetLatestPerfValueFloat("deviceGpuClockFrequencyInMHz");

            if (deviceCpuClockLevel.HasValue || deviceCpuClockFrequencyInMHz.HasValue)
            {
                string cpuLabel;
                string cpuText;
                if (deviceCpuClockLevel.HasValue && deviceCpuClockFrequencyInMHz.HasValue)
                {
                    cpuLabel = "CPU Level (Freq)";
                    cpuText  = string.Format("{0} ({1:F0} MHz)", deviceCpuClockLevel, deviceCpuClockFrequencyInMHz);
                }
                else if (deviceCpuClockLevel.HasValue)
                {
                    cpuLabel = "CPU Level";
                    cpuText  = string.Format("{0}", deviceCpuClockLevel);
                }
                else
                {
                    cpuLabel = "CPU Frequency";
                    cpuText  = string.Format("{0:F0} MHz", deviceCpuClockFrequencyInMHz);
                }
                PresentText(cpuLabel, cpuText);
            }

            if (deviceGpuClockLevel.HasValue || deviceGpuClockFrequencyInMHz.HasValue)
            {
                string cpuLabel;
                string cpuText;
                if (deviceGpuClockLevel.HasValue && deviceGpuClockFrequencyInMHz.HasValue)
                {
                    cpuLabel = "GPU Level (Freq)";
                    cpuText  = string.Format("{0} ({1:F0} MHz)", deviceGpuClockLevel, deviceGpuClockFrequencyInMHz);
                }
                else if (deviceGpuClockLevel.HasValue)
                {
                    cpuLabel = "GPU Level";
                    cpuText  = string.Format("{0}", deviceGpuClockLevel);
                }
                else
                {
                    cpuLabel = "GPU Frequency";
                    cpuText  = string.Format("{0:F0} MHz", deviceGpuClockFrequencyInMHz);
                }
                PresentText(cpuLabel, cpuText);
            }

            PresentColumnTitles("Current", "Average", "Peak");

            PresentFloatTimeInMs("Frame Time", "deltaFrameTime", 0.020f, true, true);
            PresentFloatTimeInMs("App CPU Time", "appCpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("App GPU Time", "appGpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("Compositor CPU Time", "compositorCpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("Compositor GPU Time", "compositorGpuTime", 0.020f, true, true);
            PresentFloatPercentage("CPU Util (Average)", "systemCpuUtilAveragePercentage", false, false);
            PresentFloatPercentage("CPU Util (Worst Core)", "systemCpuUtilWorstPercentage", false, false);
            PresentFloatPercentage("GPU Util", "systemGpuUtilPercentage", false, false);
        }
    }
示例#2
0
    // The actual window code goes here
    void OnGUI()
    {
        showAndroidOptions = EditorGUILayout.Foldout(showAndroidOptions, "Android Tools");

        if (showAndroidOptions)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Android SDK root path: ", androidSdkRootPath);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start Server"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.StartServer(null);
                    EditorUtility.DisplayDialog("ADB StartServer", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Kill Server"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.KillServer(null);
                    EditorUtility.DisplayDialog("ADB KillServer", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Forward Port"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.ForwardPort(remoteListeningPort, null);
                    EditorUtility.DisplayDialog("ADB ForwardPort", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                    OVRPlugin.SendEvent("device_metrics_profiler", (exitCode == 0 ? "adb_forward_success" : "adb_forward_failure"));
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            if (GUILayout.Button("Release Port"))
            {
                if (adbTool == null)
                {
                    adbTool = new OVRADBTool(androidSdkRootPath);
                }
                if (adbTool.isReady)
                {
                    int exitCode = adbTool.ReleasePort(remoteListeningPort, null);
                    EditorUtility.DisplayDialog("ADB ReleasePort", (exitCode == 0 ? "Success" : "Failure. ExitCode = " + exitCode.ToString()), "Ok");
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't locate ADBTool", adbTool.adbPath, "Ok");
                }
            }
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        GUILayout.BeginHorizontal();
        remoteListeningPort = EditorGUILayout.DelayedIntField("Remote Port", remoteListeningPort);

        if (tcpClient.connectionState == OVRNetwork.OVRNetworkTcpClient.ConnectionState.Disconnected)
        {
            if (GUILayout.Button("Connect"))
            {
                ConnectPerfMetricsTcpServer();
                pauseReceiveMetrics = false;
                OVRPlugin.SendEvent("device_metrics_profiler", "connect");
            }
        }
        else
        {
            if (tcpClient.connectionState == OVRNetwork.OVRNetworkTcpClient.ConnectionState.Connecting)
            {
                if (GUILayout.Button("Connecting ... Click again to Cancel"))
                {
                    DisconnectPerfMetricsTcpServer();
                    OVRPlugin.SendEvent("device_metrics_profiler", "cancel");
                }
            }
            else
            {
                if (GUILayout.Button("Disconnect"))
                {
                    DisconnectPerfMetricsTcpServer();
                    OVRPlugin.SendEvent("device_metrics_profiler", "disconnect");
                }

                if (GUILayout.Button(pauseReceiveMetrics ? "Continue" : "Pause"))
                {
                    pauseReceiveMetrics = !pauseReceiveMetrics;
                }
            }
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        lock (receivedMetricsList)
        {
            PresentIntProperty("Frame Count", "frameCount");
            PresentIntProperty("Dropped Frame Count", "compositorDroppedFrameCount");

            float?avgFrameTime = GetAveragePerfValueFloat("deltaFrameTime");
            if (avgFrameTime.HasValue)
            {
                float fps = 1.0f / avgFrameTime.Value;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("FPS", GUILayout.Width(labelWidth));
                EditorGUILayout.LabelField(string.Format("{0:F1}", fps));
                EditorGUILayout.EndHorizontal();
            }

            int?  deviceCpuClockLevel          = GetLatestPerfValueInt("deviceCpuClockLevel");
            int?  deviceGpuClockLevel          = GetLatestPerfValueInt("deviceGpuClockLevel");
            float?deviceCpuClockFrequencyInMHz = GetLatestPerfValueFloat("deviceCpuClockFrequencyInMHz");
            float?deviceGpuClockFrequencyInMHz = GetLatestPerfValueFloat("deviceGpuClockFrequencyInMHz");

            if (deviceCpuClockLevel.HasValue || deviceCpuClockFrequencyInMHz.HasValue)
            {
                string cpuLabel;
                string cpuText;
                if (deviceCpuClockLevel.HasValue && deviceCpuClockFrequencyInMHz.HasValue)
                {
                    cpuLabel = "CPU Level (Freq)";
                    cpuText  = string.Format("{0} ({1:F0} MHz)", deviceCpuClockLevel, deviceCpuClockFrequencyInMHz);
                }
                else if (deviceCpuClockLevel.HasValue)
                {
                    cpuLabel = "CPU Level";
                    cpuText  = string.Format("{0}", deviceCpuClockLevel);
                }
                else
                {
                    cpuLabel = "CPU Frequency";
                    cpuText  = string.Format("{0:F0} MHz", deviceCpuClockFrequencyInMHz);
                }
                PresentText(cpuLabel, cpuText);
            }

            if (deviceGpuClockLevel.HasValue || deviceGpuClockFrequencyInMHz.HasValue)
            {
                string cpuLabel;
                string cpuText;
                if (deviceGpuClockLevel.HasValue && deviceGpuClockFrequencyInMHz.HasValue)
                {
                    cpuLabel = "GPU Level (Freq)";
                    cpuText  = string.Format("{0} ({1:F0} MHz)", deviceGpuClockLevel, deviceGpuClockFrequencyInMHz);
                }
                else if (deviceGpuClockLevel.HasValue)
                {
                    cpuLabel = "GPU Level";
                    cpuText  = string.Format("{0}", deviceGpuClockLevel);
                }
                else
                {
                    cpuLabel = "GPU Frequency";
                    cpuText  = string.Format("{0:F0} MHz", deviceGpuClockFrequencyInMHz);
                }
                PresentText(cpuLabel, cpuText);
            }

            PresentColumnTitles("Current", "Average", "Peak");

            PresentFloatTimeInMs("Frame Time", "deltaFrameTime", 0.020f, true, true);
            PresentFloatTimeInMs("App CPU Time", "appCpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("App GPU Time", "appGpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("Compositor CPU Time", "compositorCpuTime", 0.020f, true, true);
            PresentFloatTimeInMs("Compositor GPU Time", "compositorGpuTime", 0.020f, true, true);
            PresentFloatPercentage("CPU Util (Average)", "systemCpuUtilAveragePercentage", false, false);
            PresentFloatPercentage("CPU Util (Worst Core)", "systemCpuUtilWorstPercentage", false, false);
            PresentFloatPercentage("GPU Util", "systemGpuUtilPercentage", false, false);
        }
    }