/// <summary> /// Runs a build for a given project content with the profiler option on and returns the result of profiling it /// </summary> private ProfilerResult BuildAndGetProfilerResult(string projectContent) { var content = CleanupFileContents(projectContent); var profilerLogger = ProfilerLogger.CreateForTesting(); var parameters = new BuildParameters { ShutdownInProcNodeOnBuildFinish = true, Loggers = new ILogger[] { profilerLogger }, DisableInProcNode = true, // This is actually important since we also want to test the serialization of the events ProjectLoadSettings = ProjectLoadSettings.ProfileEvaluation }; using (var projectCollection = new ProjectCollection()) { var project = CreateProject(content, MSBuildDefaultToolsVersion, projectCollection); var projectInstance = _buildManager.GetProjectInstanceForBuild(project); var buildRequestData = new BuildRequestData( projectInstance, new string[] {}, projectCollection.HostServices); var result = _buildManager.Build(parameters, buildRequestData); File.Delete(project.FullPath); Assert.Equal(BuildResultCode.Success, result.OverallResult); } return(profilerLogger.GetAggregatedResult(pruneSmallItems: false)); }
public static void RequestReJit(MethodBase method) { if (!IsReJitEnabled) { ThrowElevatedMockingException(); } var typeName = method.DeclaringType.IsGenericType ? string.Format("{0}[{1}]", method.DeclaringType.Name, string.Join(", ", method.DeclaringType.GetGenericArguments().Select(current => current.ToString()).ToArray())) : method.DeclaringType.Name; var methodName = method.IsGenericMethod ? string.Format("{0}[{1}]", method.Name, string.Join(", ", method.GetGenericArguments().Select(current => current.ToString()).ToArray())) : method.Name; #if DEBUG ProfilerLogger.Info("*** [MANAGED] Requesting ReJit for {0}.{1}", typeName, methodName); #endif var typeHandle = method.DeclaringType.TypeHandle; var methodToken = method.MetadataToken; IntPtr[] methodGenericArgHandles = method.IsGenericMethod ? method.GetGenericArguments().Select(type => type.TypeHandle.Value).ToArray() : null; var methodGenericArgHandlesCount = methodGenericArgHandles != null ? methodGenericArgHandles.Length : 0; bool requestSucceeded = RequestReJitImpl(typeHandle.Value, methodToken, methodGenericArgHandlesCount, methodGenericArgHandles); if (!requestSucceeded) { throw new MockException(string.Format("ReJit request failed for {0}.{1}", typeName, methodName)); } }
private static bool InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, object[] data) { if (!IsInterceptionEnabled || isFinalizerThread) { return(true); } try { ReentrancyCounter++; var method = MethodBase.GetMethodFromHandle(methodHandle, typeHandle); if (method.DeclaringType == null) { return(true); } if (method == skipMethodInterceptionOnce) { skipMethodInterceptionOnce = null; return(true); } #if DEBUG ProfilerLogger.Info("*** +++ [MANAGED] Intercepting method call for {0}.{1}", method.DeclaringType.Name, method.Name); #endif var invocation = new Invocation(data[0], method, data.Skip(2).ToArray()); if (DispatchInvocation(invocation)) { data[1] = invocation.ReturnValue; int methodArgsCount = method.GetParameters().Length; for (int i = 0; i < methodArgsCount; ++i) { data[i + 2] = invocation.Args[i]; } return(invocation.CallOriginal); } return(true); } finally { ReentrancyCounter--; } }
private static object InterceptNewobj(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, object[] data) { if (!IsInterceptionEnabled || isFinalizerThread) { return(null); } try { ReentrancyCounter++; var method = MethodBase.GetMethodFromHandle(methodHandle, typeHandle); #if DEBUG ProfilerLogger.Info("*** +++ [MANAGED] Intercepting constructor call for {0}.{1}", method.DeclaringType.Name, method.Name); #endif var invocation = new Invocation(MockingUtil.TryGetUninitializedObject(method.DeclaringType), method, data ?? new object[0]); if (DispatchInvocation(invocation)) { if (invocation.CallOriginal) { SkipMethodInterceptionOnce(method); return(null); } if (invocation.IsReturnValueSet && invocation.ReturnValue != null) { return(invocation.ReturnValue); } return(invocation.Instance); } return(null); } finally { ReentrancyCounter--; } }