Esempio n. 1
0
 public static PerfMonitor Instance()
 {
     if (gInstance == null)
     {
         gInstance = new PerfMonitor();
     }
     return(gInstance);
 }
Esempio n. 2
0
        public EmptyMsgRet OnSessionEnterWorkerReq(SessionEnterWorkerReq reqMsg)
        {
            Int64 nBeginUs   = DateTime.Now.Ticks / 10;
            Int64 nSessionID = reqMsg.SessionId;

            FFLog.Trace(string.Format("worker OnSessionEnterWorkerReq session={0}", nSessionID));

            this.funcSessionOnEnterWorker?.Invoke(nSessionID, reqMsg.FromWorker, reqMsg.ExtraData);
            PerfMonitor.Instance().AddPerf("OnEnterWorker", DateTime.Now.Ticks / 10 - nBeginUs);
            return(RPC_NONE);
        }
Esempio n. 3
0
        public object CallPythonFunc(string nameModAndFunc, object[] argsObj)
        {
            object ret      = null;
            Int64  nBeginUs = DateTime.Now.Ticks / 10;

            try
            {
                ret = m_h2call(nameModAndFunc, argsObj);
            }
            catch (Exception e)
            {
                var strArgs = string.Join(",", argsObj);
                FFLog.Error(string.Format("PyScript.CallPython:{0}({1})exception:{2}", nameModAndFunc, strArgs, e.Message));
            }
            PerfMonitor.Instance().AddPerf(string.Format("py={0}", nameModAndFunc), DateTime.Now.Ticks / 10 - nBeginUs);
            return(ret);
        }
Esempio n. 4
0
        public void HandleTimeout(object source, System.Timers.ElapsedEventArgs e)
        {
            System.DateTime currentTime = DateTime.Now;

            Int64 n = ((Int64)currentTime.Ticks) / 10000;

            m_taskTimer.RemoveAll(data =>
            {
                if (n >= data.endms)
                {
                    m_taskTmp.Add(data);
                    if (data.loop)
                    {
                        data.endms = ((Int64)currentTime.Ticks) / 10000 + data.timeoutms;
                    }
                    return(true);
                }
                return(false);
            });

            foreach (var data in m_taskTmp)
            {
                GetTaskQueue().Post(() => {
                    try
                    {
                        Int64 nBeginUs = DateTime.Now.Ticks / 10;
                        data.task();
                        if (data.timerName != null && data.timerName != "")
                        {
                            PerfMonitor.Instance().AddPerf("timer=" + data.timerName, DateTime.Now.Ticks / 10 - nBeginUs);
                        }
                    }
                    catch (Exception ex)
                    {
                        FFLog.Error("timer exception:" + ex.Message);
                        return;
                    }
                });
                if (data.loop)
                {
                    m_taskTimer.Add(data);
                }
            }
            m_taskTmp.Clear();
        }
Esempio n. 5
0
        public EmptyMsgRet OnSessionOfflineReq(SessionOfflineReq reqMsg)
        {
            Int64 nBeginUs   = DateTime.Now.Ticks / 10;
            Int64 nSessionID = reqMsg.SessionId;

            FFLog.Trace(string.Format("worker OnSessionOfflineReq! {0}", nSessionID));
            int cmd = (int)WorkerDef.OFFLINE_CMD;

            if (m_dictCmd2Func.ContainsKey(cmd) == false)
            {
                FFLog.Error(string.Format("worker cmd invalid! {0}", cmd));
                return(RPC_NONE);
            }
            byte[] data = {};
            m_dictCmd2Func[cmd].cmdHandler(nSessionID, cmd, data);
            PerfMonitor.Instance().AddPerf("OnOffline", DateTime.Now.Ticks / 10 - nBeginUs);
            return(RPC_NONE);
        }
Esempio n. 6
0
        public EmptyMsgRet OnRouteLogicMsgReq(RouteLogicMsgReq reqMsg)
        {
            Int64 nBeginUs = DateTime.Now.Ticks / 10;
            int   cmd      = reqMsg.Cmd;

            if ((cmd & 0x4000) != 0)
            {
                cmd &= ~(0x4000);
            }
            Int64 nSessionID = reqMsg.SessionId;

            if (m_dictCmd2Func.ContainsKey(cmd) == false)
            {
                FFLog.Error(string.Format("worker cmd invalid! {0}", cmd));
                return(RPC_NONE);
            }
            CmdRegInfo cmdRegInfo = m_dictCmd2Func[cmd];

            cmdRegInfo.cmdHandler(nSessionID, reqMsg.Cmd, reqMsg.Body);
            PerfMonitor.Instance().AddPerf(string.Format("cmd={0}", cmdRegInfo.cmdName), DateTime.Now.Ticks / 10 - nBeginUs);
            return(RPC_NONE);
        }