private static string GetShortInstanceName(ServiceHostBase serviceHost) { ServiceInfo serviceInfo = new ServiceInfo(serviceHost); string serviceName = serviceInfo.ServiceName; string uri = GetServiceUri(serviceHost, serviceInfo); int length = serviceName.Length + uri.Length + 2; if (length > maxCounterLength) { int count = 0; truncOptions tasks = ServicePerformanceCountersBase.GetCompressionTasks( length, serviceName.Length, uri.Length); //if necessary, compress service name to 8 chars with a 2 char hash code if ((tasks & truncOptions.service32) > 0) { count = 32; serviceName = GetHashedString(serviceName, count - hashLength, serviceName.Length - count + hashLength, true); } //if necessary, compress uri to 36 chars with a 2 char hash code if ((tasks & truncOptions.uri31) > 0) { count = 31; uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false); } } // replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name return(serviceName + "@" + uri.Replace('/', '|')); }
static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost) { // instance name is: serviceName@uri ServiceInfo serviceInfo = new ServiceInfo(serviceHost); string serviceName = serviceInfo.ServiceName; string uri; if (!TryGetFullVirtualPath(serviceHost, out uri)) { uri = serviceInfo.FirstAddress; } int length = serviceName.Length + uri.Length + 2; if (length > maxCounterLength) { int count = 0; truncOptions tasks = ServicePerformanceCountersBase.GetCompressionTasks( length, serviceName.Length, uri.Length); //if necessary, compress service name to 8 chars with a 2 char hash code if ((tasks & truncOptions.service32) > 0) { count = 32; serviceName = GetHashedString(serviceName, count - hashLength, serviceName.Length - count + hashLength, true); } //if necessary, compress uri to 36 chars with a 2 char hash code if ((tasks & truncOptions.uri31) > 0) { count = 31; uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false); } } // replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name return(serviceName + "@" + uri.Replace('/', '|')); }