Пример #1
0
        static InstanceNameTruncOptions GetCompressionTasks(int totalLen, int serviceLen, int uriLen)
        {
            InstanceNameTruncOptions bitmask = 0;

            if (totalLen > maxCounterLength)
            {
                int workingLen = totalLen;

                //note: order of if statements important (see spec)!
                if (workingLen > maxCounterLength && serviceLen > 32)
                {
                    bitmask    |= InstanceNameTruncOptions.Service32; //compress service name to 16 chars
                    workingLen -= serviceLen - 32;
                }
                if (workingLen > maxCounterLength && uriLen > 31)
                {
                    bitmask |= InstanceNameTruncOptions.Uri31; //compress uri to 31 chars
                }
            }

            return(bitmask);
        }
Пример #2
0
        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;

                InstanceNameTruncOptions tasks = GetCompressionTasks(
                    length, serviceName.Length, uri.Length);

                //if necessary, compress service name to 8 chars with a 2 char hash code
                if ((tasks & InstanceNameTruncOptions.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 & InstanceNameTruncOptions.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('/', '|'));
        }