コード例 #1
0
        void Request_profile_baseline(FunctionIDCollection functionIds, ThreadIDCollection threadIds, out Int32 hr)
        {
            var snapshot = NativeMethods.GetProfileWithRelease(out hr);

            Assert.GreaterOrEqual(hr, 0);
            Assert.IsNotNull(snapshot, "snapshot is null");
            Assert.Greater(snapshot.Length, 0, "snapshot.Length count is <= 0");

            foreach (var snap in snapshot)
            {
                //GetSnapshot will never return a null for the FunctionIDs
                Assert.IsNotNull(snap.FunctionIDs, "snapshot has a null list of function ids");

                Assert.AreNotEqual(snap.ThreadId, IntPtr.Zero, "ThreadId should be non-zero");
                if (snap.ThreadId != UIntPtr.Zero)
                {
                    threadIds?.Add(snap.ThreadId);
                }

                if (snap.ErrorCode < 0)
                {
                    Assert.AreEqual(snap.FunctionIDs.Length, 0, "non empty list of function ids was return with an error code.");
                }
                else
                {
                    Assert.AreNotEqual(snap.FunctionIDs.Length, 0, "empty list of function ids was return with an successful error code.");
                    functionIds?.AddRange(snap.FunctionIDs);
                }
            }
        }
コード例 #2
0
        public void Request_function_names_invalid_functionids()
        {
            //the second request function names should return unknown/unknown
            FunctionIDCollection functionIds = new FunctionIDCollection();

            {
                functionIds.Add(UIntPtr.Zero);
                var results = Request_function_names_baseline(functionIds);
                StringAssert.AreEqualIgnoringCase(results[0].TypeName, UnknownClass);
                StringAssert.AreEqualIgnoringCase(results[0].MethodName, UnknownMethod);
            }

            functionIds.Clear();
            {
                if (IntPtr.Size == sizeof(ulong))
                {
                    functionIds.Add(new UIntPtr(unchecked ((ulong)-1)));
                }
                else
                {
                    functionIds.Add(new UIntPtr(unchecked ((uint)-1)));
                }

                var results = Request_function_names_baseline(functionIds);
                StringAssert.AreEqualIgnoringCase(results[0].TypeName, UnknownClass);
                StringAssert.AreEqualIgnoringCase(results[0].MethodName, UnknownMethod);
            }
        }
コード例 #3
0
        public void Request_profile_n_times_request_fnames()
        {
            FunctionIDCollection functionIds = new FunctionIDCollection();

            Request_profile_baseline(functionIds);
            Request_profile_baseline(functionIds);
            Request_profile_baseline(functionIds);
            Request_function_names_baseline(functionIds);
        }
コード例 #4
0
        public void Request_profile_then_request_fnames_n_times()
        {
            FunctionIDCollection functionIds = new FunctionIDCollection();

            Request_profile_baseline(functionIds, out int hr);
            Request_function_names_baseline(functionIds);

            functionIds.Clear();
            Request_profile_baseline(functionIds, out hr);
            Request_function_names_baseline(functionIds);
        }
コード例 #5
0
        public void Request_profile_then_rfn_rfn()
        {
            //the second request function names should return unknown/unknown
            FunctionIDCollection functionIds = new FunctionIDCollection();

            Request_profile_baseline(functionIds, out int hr);
            Request_function_names_baseline(functionIds);

            var results = Request_function_names_baseline(functionIds);

            StringAssert.AreEqualIgnoringCase(results[0].TypeName, UnknownClass);
            StringAssert.AreEqualIgnoringCase(results[0].MethodName, UnknownMethod);
        }
コード例 #6
0
        public void Request_function_names_invalidargs()
        {
            //the second request function names should return unknown/unknown
            FunctionIDCollection functionIds = new FunctionIDCollection();
            IntPtr functionInfo;

            //Count is 0
            var result = NativeMethods.RequestFunctionNames(new UIntPtr[0], 0, out functionInfo);

            Assert.AreEqual(result, NativeMethods.E_INVALIDARG, "RequestFunctionNames did not return expected E_INVALIDARG when zero is specified as number of function ids");

            //ptr to fids is null
            result = NativeMethods.RequestFunctionNames(null, 15, out functionInfo);
            Assert.AreEqual(result, NativeMethods.E_INVALIDARG, "RequestFunctionNames did not return expected E_INVALIDARG when array of function ids is null");
        }
コード例 #7
0
 NativeMethods.FidTypeMethodName[] Request_function_names_baseline(FunctionIDCollection functionIds)
 {
     Assert.IsNotNull(functionIds, "functionIds is null");
     Assert.Greater(functionIds.Count, 0, "functionIds count is <= 0");
     NativeMethods.FidTypeMethodName[] results;
     try
     {
         results = NativeMethods.GetFunctionInfo(functionIds.Distinct().ToArray());
     }
     finally
     {
         NativeMethods.ShutdownThreadProfiler();
     }
     Assert.IsNotNull(results, "results from GetFunctionInfo was null");
     Assert.Greater(results.Length, 0, "results from GetFunctionInfo was empty");
     Assert.AreEqual(results[0].FunctionID, functionIds[0], "GetFunctionInfo results function id did not match");
     Assert.IsTrue(results[0].TypeName.Length != 0, "GetFunctionInfo results type name was zero length");
     Assert.IsTrue(results[0].MethodName.Length != 0, "GetFunctionInfo results method name was zero length");
     return(results);
 }
コード例 #8
0
 void Request_profile_baseline(FunctionIDCollection functionIds, ThreadIDCollection threadIds)
 {
     Request_profile_baseline(functionIds, threadIds, out Int32 _);
 }
コード例 #9
0
 void Request_profile_baseline(FunctionIDCollection functionIds)
 {
     Request_profile_baseline(functionIds, null, out Int32 _);
 }
コード例 #10
0
        public void RequestProfile_VerifyThreadIDs()
        {
            //create a number of thread that recurses to a specified depth and block on a ManualResetEvent... this thread should save their threadids (GetCurrentExecutionEngineThreadId)
            //GetSnapshot on this thread
            //Set ManualResetEvent and allow the thread/task to complete/terminate
            //verify that all of the recurse thread ids are in the snapshot
            //call ShutdownThreadProfiler.
            using (var RecurseEvent = new ManualResetEventSlim(false))
            {
                const int ThreadsToCreate = 10;
                const int FramesPerThread = 1;
                int       threadsWaiting  = 0;

                var RecurseThreadIds = new ConcurrentBag <UIntPtr>();

                RecurseEvent.Reset();

                Thread[] threads = new Thread[ThreadsToCreate];

                for (int i = 0; i != threads.Length; ++i)
                {
                    threads[i] = new Thread(() => RecurseFunc(FramesPerThread, ref threadsWaiting, RecurseThreadIds, RecurseEvent), 4096 * 16)
                    {
                        IsBackground = true
                    };
                    threads[i].Start();
                }

                while (threadsWaiting != ThreadsToCreate)
                {
                    Thread.Yield();
                }

                var tidfidmap = new ThreadIDFunctionIDMap();
                Request_profile_baseline(tidfidmap, out Int32 hr);

                //free all of the recurse threads to terminate
                RecurseEvent.Set();
                for (int i = 0; i != threads.Length; ++i)
                {
                    threads[i].Join(); threads[i] = null;
                }

                CollectionAssert.IsSubsetOf(RecurseThreadIds, tidfidmap.Keys);

                var fids = new FunctionIDCollection();
                foreach (var pr in tidfidmap)
                {
                    fids.AddRange(pr.Value);
                }
                var FidTypeMethodNames = Request_function_names_baseline(fids);

                Assert.IsNotNull(FidTypeMethodNames);
                Assert.Greater(FidTypeMethodNames.Length, 0);

                foreach (var tid in RecurseThreadIds)
                {
                    int matchingMethods = 0;
                    foreach (var fid in tidfidmap[tid])
                    {
                        foreach (var ftm in FidTypeMethodNames)
                        {
                            if (ftm.FunctionID == fid)
                            {
                                if (ftm.MethodName.Equals("RecurseFunc"))
                                {
                                    ++matchingMethods;
                                }
                                break;
                            }
                        }
                    }
                    Assert.AreEqual(matchingMethods, FramesPerThread);
                }

                NativeMethods.ShutdownThreadProfiler();
            }
        }