Exemple #1
0
        private static void WriteFileLog(ProfileSummary summary, string path)
        {
            string dayPath = DateTime.Now.ToString("yyyyMMdd");

            //1.total summary
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string detailPath = Path.Combine(path, MessageQueueTableName, "Performance");

            if (!Directory.Exists(detailPath))
            {
                Directory.CreateDirectory(detailPath);
            }
            string fileName = Path.Combine(path, "summary.log");

            File.WriteAllText(fileName, FormatTotalContent(summary));
            //entity MQ write log detail
            string detailName = Path.Combine(detailPath, dayPath + ".log");

            if (!File.Exists(detailName))
            {
                File.AppendAllText(detailName, string.Join(",", MessageQueueColumns));
            }
            File.AppendAllText(detailName, FormatDetailContent(summary));
        }
Exemple #2
0
        private static string FormatDetailContent(ProfileSummary summary)
        {
            var log = new StringBuilder();

            log.AppendLine();
            foreach (var pair in GetDetailValues(summary))
            {
                log.AppendFormat("{0},", pair.Value);
            }
            return(log.ToString().TrimEnd(','));
        }
Exemple #3
0
        private static void WriteSqlLog(ProfileSummary summary, string dbProviderName, string connectionString)
        {
            var dbProvider = DbConnectionProvider.CreateDbProvider(ConnectKey, dbProviderName, connectionString);
            var command    = dbProvider.CreateCommandStruct(MessageQueueTableName, CommandMode.Insert);

            foreach (var pair in GetDetailValues(summary))
            {
                if (pair.Key.ToLower() == MessageQueueColumns[0].ToLower())
                {
                    //ignore "id"
                    continue;
                }
                command.AddParameter(pair.Key, pair.Value);
            }
            dbProvider.ExecuteQuery(command);
        }
Exemple #4
0
        private static IEnumerable <KeyValuePair <string, object> > GetDetailValues(ProfileSummary summary)
        {
            var changeAutoCount     = summary.ChangeAutoMQ.Sum(t => t.Value.Count);
            var changeAutoPerSecond = Math.Round(changeAutoCount / summary.IntervalSecond, ColumnScale);//2位小数
            var postCount           = summary.PostMQ.Sum(t => t.Value.Count);
            var postObjectCount     = summary.PostMQ.Sum(t => t.Value.ObjectCount);
            var postPerSecond       = Math.Round(postCount / summary.IntervalSecond, ColumnScale);
            var processCount        = summary.ProcessMQ.Sum(t => t.Value.Count);
            var processObjectCount  = summary.ProcessMQ.Sum(t => t.Value.ObjectCount);
            var processPerSecond    = Math.Round(processCount / summary.IntervalSecond, ColumnScale);

            //sql
            var processSqlPerSecond = Math.Round(summary.ProcessSqlCount / summary.IntervalSecond, ColumnScale);


            return(new[]
            {
                new KeyValuePair <string, object>("Id", summary.Id),
                new KeyValuePair <string, object>("Time", MathUtils.UnixEpochTimeSpan.TotalSeconds),
                new KeyValuePair <string, object>("TotalAutoChanged", summary.ChangeAutoMQ.Sum(t => t.Value.TotalCount)),
                new KeyValuePair <string, object>("AutoChangedCount", changeAutoCount),
                new KeyValuePair <string, object>("AutoChangedPerSecond", changeAutoPerSecond),
                new KeyValuePair <string, object>("TotalPost", summary.PostMQ.Sum(t => t.Value.TotalCount)),
                new KeyValuePair <string, object>("TotalPostObject", summary.PostMQ.Sum(t => t.Value.TotalObjectCount)),
                new KeyValuePair <string, object>("PostCount", postCount),
                new KeyValuePair <string, object>("PostObjectCount", postObjectCount),
                new KeyValuePair <string, object>("PostPerSecond", postPerSecond),
                new KeyValuePair <string, object>("TotalProcess", summary.ProcessMQ.Sum(t => t.Value.TotalCount)),
                new KeyValuePair <string, object>("TotalProcessObject", summary.ProcessMQ.Sum(t => t.Value.TotalObjectCount)),
                new KeyValuePair <string, object>("ProcessCount", processCount),
                new KeyValuePair <string, object>("ProcessObjectCount", processObjectCount),
                new KeyValuePair <string, object>("ProcessPerSecond", processPerSecond),
                new KeyValuePair <string, object>("NoProcessKey", summary.TotalNoProcess),

                //sql
                new KeyValuePair <string, object>("TotalPostSql", summary.TotalPostSqlCount),
                new KeyValuePair <string, object>("TotalProcessSql", summary.TotalProcessSqlCount),
                new KeyValuePair <string, object>("TotalFailSql", summary.TotalProcessFailSqlCount),
                new KeyValuePair <string, object>("WaitSyncEntity", summary.WaitSyncEntityCount),
                new KeyValuePair <string, object>("PostSql", summary.PostSqlCount),
                new KeyValuePair <string, object>("ProcessSql", summary.ProcessSqlCount),
                new KeyValuePair <string, object>("ProcessSqlPerSecond", processSqlPerSecond),
            });
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        internal static void WriteProfileSummaryLog(ProfileSummary summary)
        {
            string path = WorkingLogPath ?? "";

            switch (StorageMode)
            {
            case ProfileStorageMode.File:
                path = Path.Combine((string.IsNullOrEmpty(path) ? MathUtils.RuntimePath : path), "Profile");
                WriteFileLog(summary, path);
                break;

            case ProfileStorageMode.Sql:
                WriteSqlLog(summary, typeof(SqlDataProvider).Name, path.Substring(4));
                break;

            case ProfileStorageMode.MySql:
                WriteSqlLog(summary, typeof(MySqlDataProvider).Name, path.Substring(6));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 static ProfileManager()
 {
     _summary = new ProfileSummary();
     _entityObjectCollection = new DictionaryExtend<string, EntityProfileCollection>();
     _sqlCollection = new DictionaryExtend<string, SqlProfileCollection>();
 }
        private static IEnumerable<KeyValuePair<string, object>> GetDetailValues(ProfileSummary summary)
        {
            var changeAutoCount = summary.ChangeAutoMQ.Sum(t => t.Value.Count);
            var changeAutoPerSecond = Math.Round(changeAutoCount / summary.IntervalSecond, ColumnScale);//2位小数
            var postCount = summary.PostMQ.Sum(t => t.Value.Count);
            var postObjectCount = summary.PostMQ.Sum(t => t.Value.ObjectCount);
            var postPerSecond = Math.Round(postCount / summary.IntervalSecond, ColumnScale);
            var processCount = summary.ProcessMQ.Sum(t => t.Value.Count);
            var processObjectCount = summary.ProcessMQ.Sum(t => t.Value.ObjectCount);
            var processPerSecond = Math.Round(processCount / summary.IntervalSecond, ColumnScale);

            //sql
            var processSqlPerSecond = Math.Round(summary.ProcessSqlCount / summary.IntervalSecond, ColumnScale);


            return new[]
            {
                new KeyValuePair<string, object>("Id", summary.Id), 
                new KeyValuePair<string, object>("Time", MathUtils.UnixEpochTimeSpan.TotalSeconds), 
                new KeyValuePair<string, object>("TotalAutoChanged", summary.ChangeAutoMQ.Sum(t => t.Value.TotalCount)), 
                new KeyValuePair<string, object>("AutoChangedCount", changeAutoCount), 
                new KeyValuePair<string, object>("AutoChangedPerSecond", changeAutoPerSecond), 
                new KeyValuePair<string, object>("TotalPost", summary.PostMQ.Sum(t => t.Value.TotalCount)), 
                new KeyValuePair<string, object>("TotalPostObject", summary.PostMQ.Sum(t => t.Value.TotalObjectCount)), 
                new KeyValuePair<string, object>("PostCount", postCount), 
                new KeyValuePair<string, object>("PostObjectCount", postObjectCount), 
                new KeyValuePair<string, object>("PostPerSecond", postPerSecond), 
                new KeyValuePair<string, object>("TotalProcess", summary.ProcessMQ.Sum(t => t.Value.TotalCount)), 
                new KeyValuePair<string, object>("TotalProcessObject", summary.ProcessMQ.Sum(t => t.Value.TotalObjectCount)), 
                new KeyValuePair<string, object>("ProcessCount", processCount), 
                new KeyValuePair<string, object>("ProcessObjectCount", processObjectCount), 
                new KeyValuePair<string, object>("ProcessPerSecond", processPerSecond), 
                new KeyValuePair<string, object>("NoProcessKey", summary.TotalNoProcess), 

                //sql
                new KeyValuePair<string, object>("TotalPostSql", summary.TotalPostSqlCount), 
                new KeyValuePair<string, object>("TotalProcessSql", summary.TotalProcessSqlCount), 
                new KeyValuePair<string, object>("TotalFailSql", summary.TotalProcessFailSqlCount), 
                new KeyValuePair<string, object>("WaitSyncEntity", summary.WaitSyncEntityCount), 
                new KeyValuePair<string, object>("PostSql", summary.PostSqlCount), 
                new KeyValuePair<string, object>("ProcessSql", summary.ProcessSqlCount), 
                new KeyValuePair<string, object>("ProcessSqlPerSecond", processSqlPerSecond), 
            };

        }
 private static string FormatDetailContent(ProfileSummary summary)
 {
     var log = new StringBuilder();
     log.AppendLine();
     foreach (var pair in GetDetailValues(summary))
     {
         log.AppendFormat("{0},", pair.Value);
     }
     return log.ToString().TrimEnd(',');
 }
 private static void WriteFileLog(ProfileSummary summary, string path)
 {
     string dayPath = DateTime.Now.ToString("yyyyMMdd");
     //1.total summary
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
     string detailPath = Path.Combine(path, MessageQueueTableName, "Performance");
     if (!Directory.Exists(detailPath))
     {
         Directory.CreateDirectory(detailPath);
     }
     string fileName = Path.Combine(path, "summary.log");
     File.WriteAllText(fileName, FormatTotalContent(summary));
     //entity MQ write log detail
     string detailName = Path.Combine(detailPath, dayPath + ".log");
     if (!File.Exists(detailName))
     {
         File.AppendAllText(detailName, string.Join(",", MessageQueueColumns));
     }
     File.AppendAllText(detailName, FormatDetailContent(summary));
 }
        private static void WriteSqlLog(ProfileSummary summary, string dbProviderName, string connectionString)
        {
            var dbProvider = DbConnectionProvider.CreateDbProvider(ConnectKey, dbProviderName, connectionString);
            var command = dbProvider.CreateCommandStruct(MessageQueueTableName, CommandMode.Insert);

            foreach (var pair in GetDetailValues(summary))
            {
                if (pair.Key.ToLower() == MessageQueueColumns[0].ToLower())
                {
                    //ignore "id"
                    continue;
                }
                command.AddParameter(pair.Key, pair.Value);
            }
            dbProvider.ExecuteQuery(command);
        }
 /// <summary>
 /// 
 /// </summary>
 internal static void WriteProfileSummaryLog(ProfileSummary summary)
 {
     string path = WorkingLogPath ?? "";
     switch (StorageMode)
     {
         case ProfileStorageMode.File:
             path = Path.Combine((string.IsNullOrEmpty(path) ? MathUtils.RuntimePath : path), "Profile");
             WriteFileLog(summary, path);
             break;
         case ProfileStorageMode.Sql:
             WriteSqlLog(summary, typeof(SqlDataProvider).Name, path.Substring(4));
             break;
         case ProfileStorageMode.MySql:
             WriteSqlLog(summary, typeof(MySqlDataProvider).Name, path.Substring(6));
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
        /// <summary>
        /// 
        /// </summary>
        public static ProfileSummary Collect()
        {
            if (!IsEnable) return null;

            Interlocked.Increment(ref _counter);
            var summary = new ProfileSummary();
            summary.Id = _counter;
            summary.IntervalSecond = DateTime.Now.Subtract(_refreshTime).TotalSeconds;
            _refreshTime = DateTime.Now;

            foreach (var pair in _entityObjectCollection)
            {
                var entityName = pair.Key;
                var obj = pair.Value;
                long postObjectCount;
                long processObjectCount;
                obj.Reset(out postObjectCount, out processObjectCount);

                var changeAutoMqSummary = new EntitySummary()
                {
                    TotalCount = obj.ChangeAutoTimes.Total,
                    Count = obj.ChangeAutoTimes.Reset()
                };

                var postMqSummary = new EntitySummary()
                {
                    TotalCount = obj.PostTimes.Total,
                    Count = obj.PostTimes.Reset(),
                    TotalObjectCount = obj.TotalPostObjectCount,
                    ObjectCount = postObjectCount
                };
                var processMqSummary = new EntitySummary()
                {
                    TotalCount = obj.ProcessTimes.Total,
                    Count = obj.ProcessTimes.Reset(),
                    TotalObjectCount = obj.TotalProcessObjectCount,
                    ObjectCount = processObjectCount
                };
                summary.ChangeAutoMQ[entityName] = changeAutoMqSummary;
                summary.PostMQ[entityName] = postMqSummary;
                summary.ProcessMQ[entityName] = processMqSummary;
                var noProcessKeys = obj.PopNoProcessKeys().ToList();
                obj.TotalNoProcessObjectCount += noProcessKeys.Count;
                summary.TotalNoProcess += obj.TotalNoProcessObjectCount;
                if (noProcessKeys.Count > 0)
                {
                    //Write error log
                    TraceLog.WriteError("Entity operation is not saved, \"{0}\" keys:{1}", entityName, string.Join(";", noProcessKeys));
                }
            }
            foreach (var pair in _sqlCollection)
            {
                var obj = pair.Value;
                summary.PostSqlCount += obj.PostTimes.Reset();
                summary.ProcessSqlCount += obj.ProcessTimes.Reset();
                summary.TotalPostSqlCount += obj.PostTimes.Total;
                summary.TotalProcessSqlCount += obj.ProcessTimes.Total;
                summary.TotalProcessFailSqlCount += obj.TotalFailCount;
            }
            WriteProfileSummaryLog(summary);
            return _summary = summary;
        }
Exemple #13
0
 static ProfileManager()
 {
     _summary = new ProfileSummary();
     _entityObjectCollection = new DictionaryExtend <string, EntityProfileCollection>();
     _sqlCollection          = new DictionaryExtend <string, SqlProfileCollection>();
 }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        public static ProfileSummary Collect()
        {
            if (!IsEnable)
            {
                return(null);
            }

            Interlocked.Increment(ref _counter);
            var summary = new ProfileSummary();

            summary.Id             = _counter;
            summary.IntervalSecond = DateTime.Now.Subtract(_refreshTime).TotalSeconds;
            _refreshTime           = DateTime.Now;

            foreach (var pair in _entityObjectCollection)
            {
                var  entityName = pair.Key;
                var  obj        = pair.Value;
                long postObjectCount;
                long processObjectCount;
                obj.Reset(out postObjectCount, out processObjectCount);

                var changeAutoMqSummary = new EntitySummary()
                {
                    TotalCount = obj.ChangeAutoTimes.Total,
                    Count      = obj.ChangeAutoTimes.Reset()
                };

                var postMqSummary = new EntitySummary()
                {
                    TotalCount       = obj.PostTimes.Total,
                    Count            = obj.PostTimes.Reset(),
                    TotalObjectCount = obj.TotalPostObjectCount,
                    ObjectCount      = postObjectCount
                };
                var processMqSummary = new EntitySummary()
                {
                    TotalCount       = obj.ProcessTimes.Total,
                    Count            = obj.ProcessTimes.Reset(),
                    TotalObjectCount = obj.TotalProcessObjectCount,
                    ObjectCount      = processObjectCount
                };
                summary.ChangeAutoMQ[entityName] = changeAutoMqSummary;
                summary.PostMQ[entityName]       = postMqSummary;
                summary.ProcessMQ[entityName]    = processMqSummary;
                var noProcessKeys = obj.PopNoProcessKeys().ToList();
                obj.TotalNoProcessObjectCount += noProcessKeys.Count;
                summary.TotalNoProcess        += obj.TotalNoProcessObjectCount;
                if (noProcessKeys.Count > 0)
                {
                    //Write error log
                    TraceLog.WriteError("Entity operation is not saved, \"{0}\" keys:{1}", entityName, string.Join(";", noProcessKeys));
                }
            }
            foreach (var pair in _sqlCollection)
            {
                var obj = pair.Value;
                summary.PostSqlCount             += obj.PostTimes.Reset();
                summary.ProcessSqlCount          += obj.ProcessTimes.Reset();
                summary.TotalPostSqlCount        += obj.PostTimes.Total;
                summary.TotalProcessSqlCount     += obj.ProcessTimes.Total;
                summary.TotalProcessFailSqlCount += obj.TotalFailCount;
            }
            WriteProfileSummaryLog(summary);
            return(_summary = summary);
        }