You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -22,4 +22,4 @@ namespace System.ServiceModel.Diagnostics
|
||||
WmiPutInstance,
|
||||
NumItems, // leave this item at the end of the list.
|
||||
}
|
||||
}
|
||||
}
|
@@ -77,9 +77,14 @@ namespace System.ServiceModel.Diagnostics
|
||||
this.instanceName = CreateFriendlyInstanceName(service, contract, uri);
|
||||
}
|
||||
|
||||
static internal string CreateFriendlyInstanceName(string service, string contract, string uri)
|
||||
private static string GetFullInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
// instance name is: serviceName.interfaceName.operationName@uri
|
||||
return String.Format("{0}.{1}@{2}", service, contract, uri);
|
||||
}
|
||||
|
||||
private static string GetShortInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
int length = service.Length + contract.Length + uri.Length + 2;
|
||||
|
||||
if (length > maxCounterLength)
|
||||
@@ -115,6 +120,32 @@ namespace System.ServiceModel.Diagnostics
|
||||
return service + "." + contract + "@" + uri.Replace('/', '|');
|
||||
}
|
||||
|
||||
internal static string CreateFriendlyInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, uri);
|
||||
|
||||
return EnsureUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
internal static string GetFriendlyInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, uri);
|
||||
|
||||
return GetUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
private static truncOptions GetCompressionTasks(int totalLen, int serviceLen, int contractLen, int uriLen)
|
||||
{
|
||||
truncOptions bitmask = 0;
|
||||
|
@@ -154,6 +154,18 @@ namespace System.ServiceModel.Diagnostics
|
||||
get { return this.endpointCounterSetInstance != null; }
|
||||
}
|
||||
|
||||
// Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
|
||||
// it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
|
||||
// method is used in situations when we need to delete the instance immediately and know the values won't be updated.
|
||||
internal void DeleteInstance()
|
||||
{
|
||||
if (this.endpointCounterSetInstance != null)
|
||||
{
|
||||
this.endpointCounterSetInstance.Dispose();
|
||||
this.endpointCounterSetInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
|
@@ -489,7 +489,7 @@ namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
if ((source & MessageLoggingSource.Malformed) != 0)
|
||||
{
|
||||
if (!TD.MessageLogWarning(data.ToString()))
|
||||
if (TD.MessageLogWarningIsEnabled() && !TD.MessageLogWarning(data.ToString()))
|
||||
{
|
||||
if (TD.MessageLogEventSizeExceededIsEnabled())
|
||||
{
|
||||
@@ -499,7 +499,7 @@ namespace System.ServiceModel.Diagnostics
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!TD.MessageLogInfo(data.ToString()))
|
||||
if (TD.MessageLogInfoIsEnabled() && !TD.MessageLogInfo(data.ToString()))
|
||||
{
|
||||
if (TD.MessageLogEventSizeExceededIsEnabled())
|
||||
{
|
||||
|
@@ -72,9 +72,15 @@ namespace System.ServiceModel.Diagnostics
|
||||
this.instanceName = CreateFriendlyInstanceName(service, contract, operationName, uri);
|
||||
}
|
||||
|
||||
static internal string CreateFriendlyInstanceName(string service, string contract, string operation, string uri)
|
||||
|
||||
private static string GetFullInstanceName(string service, string contract, string operation, string uri)
|
||||
{
|
||||
// instance name is: serviceName.interfaceName.operationName@uri
|
||||
return String.Format("{0}.{1}.{2}@{3}", service, contract, operation, uri);
|
||||
}
|
||||
|
||||
private static string GetShortInstanceName(string service, string contract, string operation, string uri)
|
||||
{
|
||||
int length = service.Length + contract.Length + operation.Length + uri.Length + 3;
|
||||
|
||||
if (length > maxCounterLength)
|
||||
@@ -117,6 +123,32 @@ namespace System.ServiceModel.Diagnostics
|
||||
return service + "." + contract + "." + operation + "@" + uri.Replace('/', '|');
|
||||
}
|
||||
|
||||
internal static string CreateFriendlyInstanceName(string service, string contract, string operation, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, operation, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, operation, uri);
|
||||
|
||||
return EnsureUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELOPERATION.OperationPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
internal static string GetFriendlyInstanceName(string service, string contract, string operation, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, operation, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, operation, uri);
|
||||
|
||||
return GetUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELOPERATION.OperationPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
static truncOptions GetCompressionTasks(int totalLen, int serviceLen, int contractLen, int operationLen, int uriLen)
|
||||
{
|
||||
truncOptions bitmask = 0;
|
||||
|
@@ -139,6 +139,18 @@ namespace System.ServiceModel.Diagnostics
|
||||
get { return this.operationCounterSetInstance != null; }
|
||||
}
|
||||
|
||||
// Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
|
||||
// it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
|
||||
// method is used in situations when we need to delete the instance immediately and know the values won't be updated.
|
||||
internal void DeleteInstance()
|
||||
{
|
||||
if (this.operationCounterSetInstance != null)
|
||||
{
|
||||
this.operationCounterSetInstance.Dispose();
|
||||
this.operationCounterSetInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
|
@@ -33,11 +33,67 @@ namespace System.ServiceModel.Diagnostics
|
||||
get;
|
||||
}
|
||||
|
||||
private static string GetInstanceNameWithHash(string instanceName, string fullInstanceName)
|
||||
{
|
||||
return String.Format("{0}{1}", instanceName, StringUtil.GetNonRandomizedHashCode(fullInstanceName).ToString("X", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
protected static string EnsureUniqueInstanceName(string categoryName, string instanceName, string fullInstanceName)
|
||||
{
|
||||
if (String.IsNullOrEmpty(categoryName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("categoryName");
|
||||
if (String.IsNullOrEmpty(instanceName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("instanceName");
|
||||
if (String.IsNullOrEmpty(fullInstanceName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("fullInstanceName");
|
||||
|
||||
try
|
||||
{
|
||||
// If the instance name is already used, append a hash of the full name to it.
|
||||
if (PerformanceCounterCategory.InstanceExists(instanceName, categoryName))
|
||||
{
|
||||
return GetInstanceNameWithHash(instanceName, fullInstanceName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If an exception is thrown, return the instance name without modification.
|
||||
}
|
||||
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
protected static string GetUniqueInstanceName(string categoryName, string instanceName, string fullInstanceName)
|
||||
{
|
||||
if (String.IsNullOrEmpty(categoryName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("categoryName");
|
||||
if (String.IsNullOrEmpty(instanceName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("instanceName");
|
||||
if (String.IsNullOrEmpty(fullInstanceName))
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNullOrEmptyString("fullInstanceName");
|
||||
|
||||
try
|
||||
{
|
||||
// If the instance name with the hash appended exists, return it.
|
||||
string nameWithHash = GetInstanceNameWithHash(instanceName, fullInstanceName);
|
||||
if (PerformanceCounterCategory.InstanceExists(nameWithHash, categoryName))
|
||||
{
|
||||
return nameWithHash;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If an exception is thrown, return the instance name without modification.
|
||||
}
|
||||
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
// remove count chars from string and add a 2 char hash code to beginning or end, as specified.
|
||||
protected static string GetHashedString(string str, int startIndex, int count, bool hashAtEnd)
|
||||
{
|
||||
string returnVal = str.Remove(startIndex, count);
|
||||
string hash = ((uint)str.GetHashCode() % 99).ToString("00", CultureInfo.InvariantCulture);
|
||||
string hash = ((uint)StringUtil.GetNonRandomizedHashCode(str) % 99).ToString("00", CultureInfo.InvariantCulture);
|
||||
return hashAtEnd ? returnVal + hash : hash + returnVal;
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,8 @@ namespace System.ServiceModel.Diagnostics
|
||||
|
||||
static class PerformanceCountersFactory
|
||||
{
|
||||
private static bool categoriesExist = false;
|
||||
|
||||
static internal ServicePerformanceCountersBase CreateServiceCounters(ServiceHostBase serviceHost)
|
||||
{
|
||||
if (!CheckPermissions())
|
||||
@@ -20,6 +22,7 @@ namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureCategoriesExistIfNeeded();
|
||||
var counters = new ServicePerformanceCountersV2(serviceHost);
|
||||
// Workaround Sys.Diag.PerformanceData problem:
|
||||
// Ensure that all three categories are initialized so other processes can still
|
||||
@@ -60,6 +63,7 @@ namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureCategoriesExistIfNeeded();
|
||||
return new EndpointPerformanceCountersV2(service, contract, uri);
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
@@ -94,6 +98,7 @@ namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureCategoriesExistIfNeeded();
|
||||
return new OperationPerformanceCountersV2(service, contract, operationName, uri);
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
@@ -139,5 +144,81 @@ namespace System.ServiceModel.Diagnostics
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If EnsureUniquePerformanceCounterInstanceName is enabled, PerformanceCountersBase.cs will be checking if instances
|
||||
// exist in each of these categories, so we need to ensure the categories all exist. This works around System.Diagnostics
|
||||
// calls using PerformanceCounterLib to cache which categories do/don't exist.
|
||||
private static void EnsureCategoriesExistIfNeeded()
|
||||
{
|
||||
if (categoriesExist || !ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OperationPerformanceCountersV2 operationCounter = null;
|
||||
EndpointPerformanceCountersV2 endpointCounter = null;
|
||||
ServicePerformanceCountersV2 serviceCounter = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELOPERATION.OperationPerfCounters) &&
|
||||
PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters) &&
|
||||
PerformanceCounterCategory.Exists(PerformanceCounterStrings.SERVICEMODELSERVICE.ServicePerfCounters))
|
||||
{
|
||||
categoriesExist = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Categories do not exist. Update PerformanceCounterLib's cache using dummy counters.
|
||||
const string dummyValue = "_WCF_Admin";
|
||||
|
||||
|
||||
// Older operating systems (such as windows 7) report the category as not existing unless a counter instance
|
||||
// has been created in it. Create one instance in each of the categories to ensure they will exist in the cache
|
||||
// that System.Diagnostics calls use.
|
||||
ServiceHost dummyServiceHost = new ServiceHost(typeof(object), new Uri("http://" + dummyValue));
|
||||
operationCounter = new OperationPerformanceCountersV2(dummyValue, dummyValue, dummyValue, dummyValue);
|
||||
endpointCounter = new EndpointPerformanceCountersV2(dummyValue, dummyValue, dummyValue);
|
||||
serviceCounter = new ServicePerformanceCountersV2(dummyServiceHost);
|
||||
|
||||
// Throw away cached categories, then read from the categories to cause the cache to be repopulated.
|
||||
PerformanceCounter.CloseSharedResources();
|
||||
PerformanceCounterCategory.Exists(dummyValue);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
// Don't have permission to read performance counters. Trace a warning.
|
||||
if (DiagnosticUtility.ShouldTraceWarning)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Warning,
|
||||
TraceCode.PerformanceCountersFailedForService,
|
||||
SR.GetString(SR.EnsureCategoriesExistFailedPermission));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Failed to ensure all of the categories exist. Catch the exception and try to create the counter anyway.
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Delete the dummy counters, we don't need them anymore.
|
||||
if (operationCounter != null)
|
||||
{
|
||||
operationCounter.DeleteInstance();
|
||||
}
|
||||
|
||||
if (endpointCounter != null)
|
||||
{
|
||||
endpointCounter.DeleteInstance();
|
||||
}
|
||||
|
||||
if (serviceCounter != null)
|
||||
{
|
||||
serviceCounter.DeleteInstance();
|
||||
}
|
||||
|
||||
categoriesExist = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -143,16 +143,31 @@ namespace System.ServiceModel.Diagnostics
|
||||
get { return (int)PerfCounters.TotalCounters; }
|
||||
}
|
||||
|
||||
static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
|
||||
private static string GetServiceUri(ServiceHostBase serviceHost, ServiceInfo serviceInfo)
|
||||
{
|
||||
// instance name is: serviceName@uri
|
||||
ServiceInfo serviceInfo = new ServiceInfo(serviceHost);
|
||||
string serviceName = serviceInfo.ServiceName;
|
||||
string uri;
|
||||
if (!TryGetFullVirtualPath(serviceHost, out uri))
|
||||
{
|
||||
uri = serviceInfo.FirstAddress;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
private static string GetFullInstanceName(ServiceHostBase serviceHost)
|
||||
{
|
||||
// instance name is: serviceName@uri
|
||||
ServiceInfo serviceInfo = new ServiceInfo(serviceHost);
|
||||
string serviceName = serviceInfo.ServiceName;
|
||||
string uri = GetServiceUri(serviceHost, serviceInfo);
|
||||
return String.Format("{0}@{1}", serviceName, uri);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -181,6 +196,32 @@ namespace System.ServiceModel.Diagnostics
|
||||
return serviceName + "@" + uri.Replace('/', '|');
|
||||
}
|
||||
|
||||
internal static string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(serviceHost);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(serviceHost);
|
||||
|
||||
return EnsureUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELSERVICE.ServicePerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
internal static string GetFriendlyInstanceName(ServiceHostBase serviceHost)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(serviceHost);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(serviceHost);
|
||||
|
||||
return GetUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELSERVICE.ServicePerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
static bool TryGetFullVirtualPath(ServiceHostBase serviceHost, out string uri)
|
||||
{
|
||||
VirtualPathExtension pathExtension = serviceHost.Extensions.Find<VirtualPathExtension>();
|
||||
|
@@ -232,6 +232,18 @@ using System.ServiceModel.Administration;
|
||||
get { return this.serviceCounterSetInstance != null; }
|
||||
}
|
||||
|
||||
// Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
|
||||
// it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
|
||||
// method is used in situations when we need to delete the instance immediately and know the values won't be updated.
|
||||
internal void DeleteInstance()
|
||||
{
|
||||
if (this.serviceCounterSetInstance != null)
|
||||
{
|
||||
this.serviceCounterSetInstance.Dispose();
|
||||
this.serviceCounterSetInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
|
@@ -554,6 +554,24 @@ namespace System.ServiceModel.Diagnostics
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
internal static ServiceModelActivity ExtractActivity(RequestContext request)
|
||||
{
|
||||
try
|
||||
{
|
||||
return TraceUtility.ExtractActivity(request.RequestMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static Guid ExtractActivityId(Message message)
|
||||
{
|
||||
if (TraceUtility.MessageFlowTracingOnly)
|
||||
|
Reference in New Issue
Block a user