示例#1
0
        public static void ToFile(string path, InternalProfile profile)
        {
            String fileData = "Category,Session Group,Session Item,Count,Average(ms),Total(ms)\r\n";

            foreach (KeyValuePair <ProfileConfig, TimingInfo> time in profile.Timers.OrderBy(key => key.Key.Tag))
            {
                fileData += $"{time.Key.Category}," +
                            $"{time.Key.SessionGroup}," +
                            $"{time.Key.SessionItem}," +
                            $"{time.Value.Count}," +
                            $"{time.Value.AverageTime / PerformanceCounter.TicksPerMillisecond}," +
                            $"{time.Value.TotalTime / PerformanceCounter.TicksPerMillisecond}\r\n";
            }

            // Ensure file directory exists before write
            FileInfo fileInfo = new FileInfo(path);

            if (fileInfo == null)
            {
                throw new Exception("Unknown logging error, probably a bad file path");
            }
            if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
            {
                Directory.CreateDirectory(fileInfo.Directory.FullName);
            }

            File.WriteAllText(fileInfo.FullName, fileData);
        }
示例#2
0
        public static bool ProfilingEnabled()
        {
#if USE_PROFILING
            if (!_settings.Enabled)
            {
                return(false);
            }

            if (_profileInstance == null)
            {
                _profileInstance = new InternalProfile(_settings.History, _settings.MaxFlags);
            }

            return(true);
#else
            return(false);
#endif
        }