Exemplo n.º 1
0
        internal void Start()
        {
            Log.I($"Started com.unity.simulation.core {kVersionString}");

            StartNotification?.Invoke();

            var chunk_size_bytes = Configuration.Instance.SimulationConfig.chunk_size_bytes;
            var chunk_timeout_ms = Configuration.Instance.SimulationConfig.chunk_timeout_ms;

            if (chunk_size_bytes > 0 && chunk_timeout_ms > 0)
            {
                ChunkedUnityLog.CaptureToFile
                (
                    Path.Combine(GetDirectoryFor(DataCapturePaths.Chunks), kPlayerLogFileName),
                    true,
                    chunk_size_bytes,
                    (float)chunk_timeout_ms / 1000.0f
                );
            }

            if (Options.uploadFilesFromPreviousRun && Configuration.Instance.IsSimulationRunningInCloud())
            {
                UploadTracesFromPreviousRun(Configuration.Instance.GetStorageBasePath());
            }
        }
Exemplo n.º 2
0
        internal void LateUpdate()
        {
#if !UNITY_2019_3_OR_NEWER
            var jobsInFlight = _requestsInFlight.Where(r => r.Key.jobsInFlight > 0);
            if (jobsInFlight.Any())
            {
                JobHandle.ScheduleBatchedJobs();
            }
#endif
            if (_shutdownRequested)
            {
                if (!_finalUploadsDone)
                {
#if !UNITY_EDITOR
                    // We have to wait until requests that have been created but not started, get executed.
                    // Otherwise they won't do their work when the CompleteTrackedRequests(true) is called.
                    // In editor playmode this is disabled, since scripts will only execute for 1 frame when
                    // exiting playmode, and so the rest of the shutdown will not occur if we wait at all.
                    if (AnyRequestsHaveNotStarted())
                    {
                        return;
                    }
#endif
                    ShutdownNotification?.Invoke();

                    // Comlete all requests that are outstanding.
                    CompleteTrackedRequests(true);

                    ChunkedUnityLog.EndCapture();

                    if (ProfilerEnabled)
                    {
                        Log.V("Disabling the Profiler to flush it down to the file system");
                        Profiler.enabled         = false;
                        Profiler.enableBinaryLog = false;
                    }

                    try
                    {
                        var profilerLog = Path.Combine(GetDirectoryFor(DataCapturePaths.Logs), kProfilerLogFileName);
                        if (File.Exists(profilerLog))
                        {
                            Log.V("Profiler file length: " + new FileInfo(profilerLog).Length);
                            ConsumerFileProduced(profilerLog, true);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.V($"Exception ocurred uploading profiler log: {e.ToString()}");
                    }

                    // Note: It's super important that this flag is set after the two calls to ConsumerFileProduced.
                    // If set before, they will be rejected, and if not set after, then the next frame, they will be queued again.
                    // This has the effect of preventing a shutdown indefinitely. Anything that interrupts the control flow like
                    // await can cause the setting of this flag to be deferred, allowing the next tick to queue another file.
                    _finalUploadsDone = true;
                    Log.V("Final uploads completed.");
                }

                if (readyToQuit)
                {
                    Log.V("Application quit");
                    Application.Quit();
                }
            }
        }