Exemplo n.º 1
0
        public void add_info(RECORD_INFO p)
        {
            lock (_map_stat_info)
            {
                STAT_INFO info;
                if (_map_stat_info.TryGetValue(p.op, out info))
                {
                    add_stat_2_info(p, ref info);
                }
                else
                {
                    info = new STAT_INFO();
                    add_stat_2_info(p, ref info);
                    _map_stat_info.Add(p.op, info);
                }
            }

            /* has problem
             * if(p.errcode != -30000)   //业务不存在的错误码,如果业务不存在,不添加业务统计和创建相关的文件
             * {
             *  Dictionary<string, STAT_INFO> busi_stat;
             *  if (_map_biz_stat.TryGetValue(p.biz_name, out busi_stat))
             *  { }
             *  else
             *  {
             *      busi_stat = new Dictionary<string, STAT_INFO>();
             *      _map_biz_stat.Add(p.biz_name, busi_stat);
             *  }
             *
             *
             *  STAT_INFO busi_stat_info;
             *  if (busi_stat.TryGetValue(p.op, out busi_stat_info))
             *  {
             *      add_stat_2_info(p, ref busi_stat_info);
             *  }
             *  else
             *  {
             *      busi_stat_info = new STAT_INFO();
             *      add_stat_2_info(p, ref busi_stat_info);
             *      busi_stat.Add(p.op, info);
             *  }
             * }*/
            return;
        }
Exemplo n.º 2
0
        public void write_stat_info_2_file(Dictionary <string, STAT_INFO> map_stat_info, string biz_id, System.DateTime _cur_time)
        {
            List <FileStream> vec_fp = new List <FileStream>();
            //_cur_time = now_time;
            string file;;

            try
            {
                if (biz_id.Length == 0)
                {
                    file = String.Format("{0}.{1}.log", _log_file, _cur_time.ToString(DateFormat));
                    checkAndCreateFile(file);
                    FileStream fs = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                    if (fs != null)
                    {
                        vec_fp.Add(fs);
                    }
                    file = String.Format("{0}.report", _log_file);
                    checkAndCreateFile(file);
                    FileStream fs2 = new FileStream(file, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
                    if (fs2 != null)
                    {
                        vec_fp.Add(fs2);
                    }
                }
                else
                {
                    file = String.Format("{0}_{1}.{2}.log", _log_file, biz_id, _cur_time.ToString(DateFormat));
                    checkAndCreateFile(file);
                    FileStream fs = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                    if (fs != null)
                    {
                        vec_fp.Add(fs);
                    }

                    file = String.Format(" {0}_{1}.report", _log_file, biz_id);
                    checkAndCreateFile(file);
                    FileStream fs2 = new FileStream(file, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
                    if (fs2 != null)
                    {
                        vec_fp.Add(fs2);
                    }
                }

                if (vec_fp.Count == 0)
                {
                    return;
                }

                if (map_stat_info.Count == 0)
                {
                    foreach (var item in vec_fp)
                    {
                        item.Close();
                    }
                    return;
                }

                //- print stat info
                string temp = string.Format("{0}\r\n", _cur_time.ToString(TimeFormat));
                myprintf(vec_fp, temp);

                temp = string.Format(" ===============================================================================================\r\n");
                myprintf(vec_fp, temp);

                temp = string.Format("     Operation| {0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7}", "Success", "Error", "Err_nor", "Err_err", "Cost_t", "Suc_t", "Fail_t");
                myprintf(vec_fp, temp);

                foreach (var item in _vec_cost_time)
                {
                    string tmp = string.Format(">{0}", item);

                    tmp = string.Format(" {0,7}", tmp);
                    myprintf(vec_fp, tmp);
                }
                myprintf(vec_fp, "\r\n");
                myprintf(vec_fp, " -----------------------------------------------------------------------------------------------\r\n");
                int   total_suc      = 0;
                int   total_err      = 0;
                int   total_err_nor  = 0;
                int   total_err_fail = 0;
                int[] cost_t_num     = new int[50];


                foreach (var it in map_stat_info)
                {
                    STAT_INFO info     = it.Value;
                    int       cost_t   = 0;
                    int       suc_c_t  = 0;
                    int       fail_c_t = 0;
                    if (info.succ_num + info.err_num > 0)
                    {
                        cost_t = (int)info.all_total_t / (info.succ_num + info.err_num);
                    }
                    if (info.succ_num > 0)
                    {
                        suc_c_t = (int)info.suc_total_t / info.succ_num;
                    }
                    if (info.err_num > 0)
                    {
                        fail_c_t = (int)info.err_total_t / info.err_num;
                    }
                    temp = string.Format("{0,14}| {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7}",
                                         it.Key, info.succ_num, info.err_num, info.err_normal, info.err_fail,
                                         cost_t, suc_c_t, fail_c_t);

                    myprintf(vec_fp, temp);

                    int i = 0;
                    foreach (var ii in _vec_cost_time)
                    {
                        int num = 0;
                        info.map_time.TryGetValue(ii, out num);
                        temp = string.Format(" {0,7}", num);
                        myprintf(vec_fp, temp);

                        cost_t_num[i] += num;
                        i++;
                    }
                    myprintf(vec_fp, "\r\n");
                    total_suc      += info.succ_num;
                    total_err      += info.err_num;
                    total_err_nor  += info.err_normal;
                    total_err_fail += info.err_fail;
                }
                myprintf(vec_fp, " -----------------------------------------------------------------------------------------------\r\n");

                temp = string.Format("{0,14}  {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7}", "total", total_suc, total_err, total_err_nor, total_err_fail, "/", "/", "/");
                myprintf(vec_fp, temp);

                for (int i = 0; i < _vec_cost_time.Count; i++)
                {
                    temp = string.Format(" {0,7}", cost_t_num[i]);
                    myprintf(vec_fp, temp);
                }
                myprintf(vec_fp, "\r\n");

                //- print size
                myprintf(vec_fp, "\r\n");
                bool is_has_size = false;
                foreach (var it in map_stat_info)
                {
                    STAT_INFO info = it.Value;
                    if (info.size > 0)
                    {
                        is_has_size = true;
                        temp        = string.Format("{0}_size: {1}\r\n", it.Key, info.size);
                        myprintf(vec_fp, temp);
                    }
                }
                //- print err distributed
                if (is_has_size)
                {
                    myprintf(vec_fp, "\r\n");
                }

                myprintf(vec_fp, "\r\n\r\n\r\n\r\n");
                //- end

                map_stat_info.Clear();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally {
                if (vec_fp != null && vec_fp.Count != 0)
                {
                    foreach (var item in vec_fp)
                    {
                        if (item != null)
                        {
                            item.Close();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public int add_stat_2_info(RECORD_INFO p, ref STAT_INFO info)
        {
            //STAT_INFO &info = _map_stat_info[p->op];

            info.all_total_t += p.cost_t;

            for (int i = _vec_cost_time.Count - 1; i >= 0; i--)
            {
                if (p.cost_t > _vec_cost_time[i])
                {
                    int num;
                    if (info.map_time.TryGetValue(_vec_cost_time[i], out num))
                    {
                        info.map_time[_vec_cost_time[i]]++;
                    }
                    else
                    {
                        info.map_time.Add(_vec_cost_time[i], 1);
                    }
                    break;
                }
            }

            if (p.errcode == 1)
            {
                info.succ_num++;
                info.suc_total_t += p.cost_t;
                info.size        += p.size;
            }
            else
            {
                int count = 0;
                if (info.map_ip.TryGetValue(p.ip, out count))
                {
                    info.map_ip[p.ip]++;
                }
                else
                {
                    info.map_ip.Add(p.ip, 1);
                }

                if (info.map_uin.TryGetValue(p.uin, out count))
                {
                    info.map_uin[p.uin]++;
                }
                else
                {
                    info.map_uin.Add(p.uin, 1);
                }
                info.err_total_t += p.cost_t;

                if (info.map_err.TryGetValue(p.errcode, out count))
                {
                    info.map_err[p.errcode]++;
                }
                else
                {
                    info.map_err.Add(p.errcode, 1);
                }

                info.err_num++;
                if (_map_normal_err.ContainsKey(p.errcode))
                {
                    info.err_normal++;
                }
                else
                {
                    info.err_fail++;
                }
            }
            return(0);
        }