Пример #1
0
        private void CodeHelper_FinishedExecution(object sender, EventArgs e)
        {
            new PermissionSet(PermissionState.Unrestricted).Assert();
            try
            {
                _memoryUsedForExecution = AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize - _memoryUsedAfterCompilation;
                Debug.WriteLine("Finished execution");

                // we just disable memory checking, as this thread checking is very memory expensive, and it will make false alarms
                _memoryUsedAfterCompilation = -1;
                ThreadsInfo threadInfo = ThreadsInfo.Gather();
                var         delta      = Math.Abs(ThreadsInfo.CalculateDifference(_threadsBefore, threadInfo));
                this.AreThreadsAlive = delta != 0;
            }
            catch (ThreadAbortException)
            {
                // it means that execution timeout was exceeded.
                // we might need to iterate over existing threads to Kill them somehow......
                throw;
            }
            finally
            {
                PermissionSet.RevertAssert();
            }
        }
Пример #2
0
        private RunStats GatherStatistics()
        {
            _executeTime = DateTime.Now - _runAt - _compileTime;

            var threadsInfo = ThreadsInfo.Gather();
            // save CPU just per execution thread, not for whole process
            var procThread = threadsInfo.Threads.FirstOrDefault(t => t.Id == _executingThreadID);

            if (procThread != null)
            {
                _cpuTime = procThread.TotalProcessorTime;
            }

            // if compilation was unsuccessfull, then we need to return 0, as we don't know how many memory was used
            if (_memoryUsedForExecution < 0 && _memoryUsedAfterCompilation > 0)
            {
                _memoryUsedForExecution = AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize - _memoryUsedAfterCompilation;
            }

            return(new RunStats()
            {
                RunAt = _runAt,
                CompileTime = _compileTime,
                ExecuteTime = _executeTime,
                MemoryUsage = _memoryUsedForExecution < 0 ? 0 : _memoryUsedForExecution,                          // in case if there are compiler errors, than we don't measure memory
                CpuUsage = _cpuTime
            });
        }
Пример #3
0
        private void CodeHelper_StartingExecution(object sender, EventArgs e)
        {
            new PermissionSet(PermissionState.Unrestricted).Assert();

            // we start here monitoring thread
            _compilationCompleted.Set();
            _threadsBefore = ThreadsInfo.Gather();

            Debug.WriteLine("Initial thread info gathered");

            _executingThreadID          = WinApiHelper.GetCurrentThreadId();
            _compileTime                = DateTime.Now - _runAt;
            _memoryUsedAfterCompilation = AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize;
            PermissionSet.RevertAssert();
        }