private static void Dynamic_All(TraceEvent obj) { if (obj.EventName.Equals("EventCounters")) { IDictionary <string, object> payloadVal = (IDictionary <string, object>)(obj.PayloadValue(0)); IDictionary <string, object> payloadFields = (IDictionary <string, object>)(payloadVal["Payload"]); ICounterPayload payload = payloadFields.Count == 6 ? (ICounterPayload) new IncrementingCounterPayload(payloadFields) : (ICounterPayload) new CounterPayload(payloadFields); string displayName = payload.GetDisplay(); if (string.IsNullOrEmpty(displayName)) { displayName = payload.GetName(); } if (string.Compare(displayName, "GC Heap Size") == 0 && Convert.ToInt32(payload.GetValue()) > threshold) { Console.WriteLine("Memory threshold has been breached...."); System.Diagnostics.Process process = System.Diagnostics.Process.GetProcessById(pid); System.Diagnostics.ProcessModule coreclr = process.Modules.Cast <System.Diagnostics.ProcessModule>().FirstOrDefault(m => string.Equals(m.ModuleName, "libcoreclr.so")); if (coreclr == null) { Console.WriteLine("Unable to locate .NET runtime associated with this process!"); Environment.Exit(1); } else { string runtimeDirectory = Path.GetDirectoryName(coreclr.FileName); string createDumpPath = Path.Combine(runtimeDirectory, "createdump"); if (!File.Exists(createDumpPath)) { Console.WriteLine("Unable to locate 'createdump' tool in '{runtimeDirectory}'"); Environment.Exit(1); } var createdump = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo() { FileName = createDumpPath, Arguments = $"--name coredump --withheap {pid}", }, EnableRaisingEvents = true, }; createdump.Start(); createdump.WaitForExit(); Environment.Exit(0); } } } }
public void CounterPayloadReceived(string providerName, ICounterPayload payload, bool _) { if (builder.Length > flushLength) { File.AppendAllText(_output, builder.ToString()); builder.Clear(); } builder.Append($"{{ \"timestamp\": \"{DateTime.Now.ToString("u")}\", "); builder.Append($" \"provider\": \"{providerName}\", "); builder.Append($" \"name\": \"{payload.GetDisplay()}\", "); builder.Append($" \"counterType\": \"{payload.GetCounterType()}\", "); builder.Append($" \"value\": {payload.GetValue()} }},"); }
public void CounterPayloadReceived(string providerName, ICounterPayload payload, bool _) { if (builder.Length > flushLength) { File.AppendAllText(_output, builder.ToString()); builder.Clear(); } builder.Append(DateTime.UtcNow.ToString() + ","); builder.Append(providerName + ","); builder.Append(payload.GetDisplay() + ","); builder.Append(payload.GetCounterType() + ","); builder.Append(payload.GetValue() + "\n"); }
public void CounterPayloadReceived(string providerName, ICounterPayload payload, bool _) { if (builder.Length > flushLength) { File.AppendAllText(_output, builder.ToString()); builder.Clear(); } builder .Append("{ \"timestamp\": \"").Append(DateTime.Now.ToString("u")).Append("\", ") .Append(" \"provider\": \"").Append(providerName).Append("\", ") .Append(" \"name\": \"").Append(payload.GetDisplay()).Append("\", ") .Append(" \"counterType\": \"").Append(payload.GetCounterType()).Append("\", ") .Append(" \"value\": ").Append(payload.GetValue().ToString(CultureInfo.InvariantCulture)).Append(" },"); }
public void CounterPayloadReceived(string providerName, ICounterPayload payload, bool _) { if (builder.Length > flushLength) { File.AppendAllText(_output, builder.ToString()); builder.Clear(); } builder .Append(DateTime.UtcNow.ToString()).Append(',') .Append(providerName).Append(',') .Append(payload.GetDisplay()).Append(',') .Append(payload.GetCounterType()).Append(',') .Append(payload.GetValue().ToString(CultureInfo.InvariantCulture)).Append('\n'); }