Beispiel #1
0
        public static JStackDump ParseJstackLog(string log)
        {
            JStackDump        stackDump = new JStackDump();
            List <JavaThread> threads   = new List <JavaThread>();

            stackDump.Threads = threads;

            JavaThread currentThread = null;

            foreach (var line in File.ReadAllLines(log))
            {
                if (line.StartsWith("Thread "))
                {
                    string     state    = string.Empty;
                    int        threadId = JavaThread.GetThreadIdandState(line, out state);
                    JavaThread j        = new JavaThread
                    {
                        Id        = threadId,
                        State     = state,
                        CallStack = new List <string>()
                    };

                    threads.Add(j);
                    currentThread = j;
                }
                else
                {
                    if (currentThread == null)
                    {
                        if (line.ToLower().Contains("Java-level deadlock".ToLower()))
                        {
                            stackDump.DeadlockMessage = line;
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(stackDump.DeadlockMessage))
                            {
                                if (!string.IsNullOrWhiteSpace(line))
                                {
                                    stackDump.DeadlockMessage += Environment.NewLine + line;
                                }
                            }
                        }

                        continue;
                    }
                    else
                    {
                        if (line.StartsWith(" - "))
                        {
                            currentThread.CallStack.Add(line.Replace(" - ", ""));
                        }
                    }
                }
            }

            foreach (var t in threads)
            {
                t.CallStackHash = string.Join(",", t.CallStack).GetHashCode();
            }

            return(stackDump);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            m_jStackLog  = args[0];
            m_OutputPath = args[1];

            if (!IsValidFile())
            {
                return;
            }

            DaaS.Logger.Init(m_jStackLog, m_OutputPath, "jStackAnalyzer", false);

            JavaThreadParserStats stats = new JavaThreadParserStats
            {
                StatsType     = "JavaThreadParserStats",
                ActivityId    = DaaS.Logger.ActivityId,
                SiteName      = DaaS.Logger.SiteName,
                TraceFileName = m_jStackLog,
            };

            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                DaaS.Logger.LogDiagnoserEvent($"Opening JStack LogFile {m_jStackLog} and outputPath is { m_OutputPath}");


                m_InstanceName     = GetMachineName(m_jStackLog);
                stats.InstanceName = m_InstanceName;

                DaaS.Logger.LogDiagnoserVerboseEvent($"Instance name is { m_InstanceName}");

                m_OutputPathWithInstanceName = Path.Combine(m_OutputPath, m_InstanceName);

                Directory.CreateDirectory(Path.Combine(m_OutputPathWithInstanceName, "reportdata"));

                CopyStaticContent(m_OutputPath);

                var stackDump = JavaThread.ParseJstackLog(m_jStackLog);
                stopWatch.Stop();
                stats.TimeToParseLogInSeconds = stopWatch.Elapsed.TotalSeconds;

                stackDump.FileName     = Path.GetFileName(m_jStackLog);
                stackDump.Timestamp    = DateTime.Now.ToString("u");
                stackDump.SiteName     = DaaS.Logger.SiteName;
                stackDump.FullFilePath = m_jStackLog;
                stackDump.MachineName  = m_InstanceName;

                using (StreamWriter file = File.CreateText(Path.Combine(m_OutputPathWithInstanceName, "reportdata", "stackDump.json")))
                {
                    var jsonWriter = new JsonTextWriter(file)
                    {
                        Formatting = Formatting.Indented
                    };
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(jsonWriter, stackDump);
                }

                DaaS.Logger.TraceStats(JsonConvert.SerializeObject(stats));
            }
            catch (Exception ex)
            {
                DaaS.Logger.LogDiagnoserErrorEvent("Failed while analyzing the jstacklog", ex);
                DaaS.Logger.TraceFatal($"Failed while analyzing the trace with exception - {ex.GetType().ToString()}: {ex.Message}", false);
            }
        }