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); }
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); }
// 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(); } }