Ejemplo n.º 1
0
        private static void SampleCpu(ClrRuntime runtime)
        {
            foreach (ClrThread thread in runtime.Threads)
            {
                StringBuilder sb = new StringBuilder();

                for (int i = thread.StackTrace.Count - 1; i >= 0; i--)
                {
                    ClrStackFrame stackFrame = thread.StackTrace[i];
                    if (!string.IsNullOrWhiteSpace(stackFrame.Method?.Type?.Name) ||
                        !string.IsNullOrWhiteSpace(stackFrame.Method?.Name))
                    {
                        sb.Append($"{stackFrame.Method?.Type?.Name}.{stackFrame.Method?.Name};");
                    }
                }

                // Trim the last ';'
                if (sb.Length > 0 && sb[sb.Length - 1] == ';')
                {
                    sb.Length = sb.Length - 1;
                }

                string stackString = sb.ToString();
                if (!string.IsNullOrWhiteSpace(stackString))
                {
                    ReportStackTrace(stackString);
                }

                runtime.Flush();
            }
        }
Ejemplo n.º 2
0
 void Flush()
 {
     clrRuntime.Flush();
     toClrThread.Clear();
     toClrThreadInitd = false;
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Flushes the dac cache.  This function MUST be called any time you expect to call the same function
 ///     but expect different results.  For example, after walking the heap, you need to call Flush before
 ///     attempting to walk the heap again.  After calling this function, you must discard ALL ClrMD objects
 ///     you have cached other than DataTarget and ClrRuntime and re-request the objects and data you need.
 ///     (E.G. if you want to use the ClrHeap object after calling flush, you must call ClrRuntime.GetHeap
 ///     again after Flush to get a new instance.)
 /// </summary>
 /// <inheritdoc />
 public void Flush()
 {
     Runtime.Flush();
 }
Ejemplo n.º 4
0
 public void Flush()
 {
     m_runtime.Flush();
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            while (true)
            {
                Process[] dllhost = Process.GetProcessesByName("dllhost");

                Console.ReadLine();

                foreach (Process process in dllhost)
                {
                    try
                    {
                        if (!NativeMethods.Is64Bit(process))
                        {
                            DataTarget dt = DataTarget.AttachToProcess(process.Id, 5000, AttachFlag.Passive);

                            // Just Native Modules (not managed)
                            // foreach (ModuleInfo md in dt.EnumerateModules())
                            // {
                            //     Console.WriteLine("PID: {0}, Description: {1}", process.Id, md.FileName);
                            // }

                            // Also managed modules
                            // First, loop through each Clr in the process (there may be
                            // multiple in the side-by-side scenario).
                            foreach (ClrInfo clrVersion in dt.ClrVersions)
                            {
                                ClrRuntime runtime = clrVersion.CreateRuntime();

                                foreach (ClrModule module in runtime.Modules)
                                {
                                    if (module.IsFile)
                                    {
                                        Console.WriteLine("Process: {0}, Module: {1}, Arq: {2}", process.Id, module.FileName, NativeMethods.Is64Bit(process));
                                    }
                                }

                                /*
                                 * Note that ClrMD builds state in caches with every API call.
                                 * Since the process is live and constantly changing this means
                                 * subsequent calls to ClrRuntime.Modules will get the same
                                 * data back over and over. Instead you need to call
                                 * ‘ClrRuntime.Flush’ if your reuse the runtime object to check
                                 * the module list repeatedly:
                                 */

                                /*
                                 * Uncomment this if you ever loop through ClrRuntime.Modules
                                 * again, expecting updated results.
                                 */
                                runtime.Flush();
                            }
                        }
                        else
                        {
                            Console.WriteLine("Process: {0}, is x64", process.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Oooops... This broke: {0}", ex.Message);
                    }
                }
            }
        }