示例#1
0
        public RpcServiceDecorator(T serviceObj) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                RpcServiceMethodAttribute methodAttr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                string methodName = method.Name;

                RpcServiceMethod m = new RpcServiceDecorator <T> .RpcServiceMethod();

                m.RatePerSecond = category.CreateCounter(methodName + " /sec.", PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount    = category.CreateCounter(methodName + " Total.", PerformanceCounterType.NumberOfItems32);
                m.TotalFailed   = category.CreateCounter(methodName + " Failed.", PerformanceCounterType.NumberOfItems32);
                m.Concurrent    = category.CreateCounter(methodName + " Concurrent.", PerformanceCounterType.NumberOfItems32);
                m.Method        = method;

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
示例#2
0
        public RpcServiceDecorator(T serviceObj, string serviceName) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            if (!string.IsNullOrEmpty(serviceName))
            {
                p_serviceName = serviceName;
            }
            else
            {
                p_serviceName = serviceAttr.ServiceName;
            }

            _serviceObj = serviceObj;
            _methods    = new HybridDictionary <string, RpcServiceMethod>();

            bool enableCounter = serviceAttr.EnableCounters == RpcPerformanceCounterMode.Both || serviceAttr.EnableCounters == RpcPerformanceCounterMode.Server;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string           methodName = method.Name;
                RpcServiceMethod m;

                RpcServiceBatchMethodAttribute battr = AttributeHelper.TryGetAttribute <RpcServiceBatchMethodAttribute>(method);
                if (battr != null)
                {
                    if (!string.IsNullOrEmpty(battr.MethodName))
                    {
                        methodName = battr.MethodName;
                    }

                    m = new RpcServiceBatchMethod(serviceObj, category, methodName, method, enableCounter);
                }
                else
                {
                    RpcServiceMethodAttribute attr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                    if (!string.IsNullOrEmpty(attr.MethodName))
                    {
                        methodName = attr.MethodName;
                    }

                    m = new RpcServiceMethod(serviceObj, category, methodName, method, enableCounter);
                }

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
示例#3
0
        // V4 新增模式
        public void Sample2()
        {
            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("Imps:SampleCategory", PerformanceCounterCategoryType.MultiInstance);
            Dictionary<int, IICPerformanceCounter> counters = new Dictionary<int, IICPerformanceCounter>();
            for (int i = 0; i < 5; i++) {
                counters.Add(i, category.CreateCounter("SampleCounter-" + i, PerformanceCounterType.RateOfCountsPerSecond32));
            }
            IICPerformanceCounterFactory.GetCounters(category);

            for (int i = 0; i < 5; i++) {
                counters[i].Increment();
            }
        }
        internal RpcTransparentService(T serviceObj, string serviceUrl)
            : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;
            _serviceUrl   = serviceUrl;

            IICPerformanceCounterCategory category =
                new IICPerformanceCounterCategory("rpc:" + p_serviceName,
                                                  PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string methodName = method.Name;


                DynamicMethod dm = new DynamicMethod("fun", typeof(object[]),
                                                     new[] { typeof(RpcServerContext) });

                RpcServiceMethod m = new RpcServiceMethod();
                m.RatePerSecond = category.CreateCounter(methodName + " /sec.",
                                                         PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount = category.CreateCounter(methodName + " Total.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.TotalFailed = category.CreateCounter(methodName + " Failed.",
                                                       PerformanceCounterType.NumberOfItems32);
                m.Concurrent = category.CreateCounter(methodName + " Concurrent.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.Method = method;

                RpcGetArgsHelper.RegisterMethod(p_serviceName, m);

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
示例#5
0
 public static void GetCounters(IICPerformanceCounterCategory category, string instanceName)
 {
     IICPerformanceCounterMananger.CreateCounters(instanceName, category._categoryAttribute, category._counters);
 }
示例#6
0
 public static void GetCounters(IICPerformanceCounterCategory category)
 {
     GetCounters(category, string.Empty);
 }