changeset 185:4c522061af03

Bug 3253: Cause string of ResourceExhausted should be collected Reviewed-by: ykubota https://github.com/HeapStats/heapstats/pull/62
author Yasumasa Suenaga <yasuenag@gmail.com>
date Tue, 13 Dec 2016 12:20:11 +0900
parents 4b22a335c282
children fe7e9fae9d25
files ChangeLog agent/src/heapstats-engines/heapstatsMBean.cpp agent/src/heapstats-engines/logMain.cpp agent/src/heapstats-engines/logManager.cpp agent/src/heapstats-engines/logManager.hpp
diffstat 5 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Dec 13 12:19:12 2016 +0900
+++ b/ChangeLog	Tue Dec 13 12:20:11 2016 +0900
@@ -1,6 +1,7 @@
 2016-12-13  Yasumasa Suenaga <yasuenag@gmail.com>
 
 	* Bug 3262: Add IntelliJ IDEA support
+	* Bug 3253: Cause string of ResourceExhausted should be collected
 
 2016-12-12  Yasumasa Suenaga <yasuenag@gmail.com>
 
--- a/agent/src/heapstats-engines/heapstatsMBean.cpp	Tue Dec 13 12:19:12 2016 +0900
+++ b/agent/src/heapstats-engines/heapstatsMBean.cpp	Tue Dec 13 12:20:11 2016 +0900
@@ -631,8 +631,8 @@
  * \return Result of this call.
  */
 JNIEXPORT jboolean JNICALL InvokeLogCollection(JNIEnv *env, jobject obj) {
-  int ret =
-      logManager->collectLog(NULL, env, Signal, (TMSecTime)getNowTimeSec());
+  int ret = logManager->collectLog(NULL, env, Signal,
+                                   (TMSecTime)getNowTimeSec(), "JMX event");
   return ret == 0 ? JNI_TRUE : JNI_FALSE;
 }
 
@@ -645,6 +645,6 @@
  */
 JNIEXPORT jboolean JNICALL InvokeAllLogCollection(JNIEnv *env, jobject obj) {
   int ret = logManager->collectLog(NULL, env, AnotherSignal,
-                                   (TMSecTime)getNowTimeSec());
+                                   (TMSecTime)getNowTimeSec(), "JMX event");
   return ret == 0 ? JNI_TRUE : JNI_FALSE;
 }
--- a/agent/src/heapstats-engines/logMain.cpp	Tue Dec 13 12:19:12 2016 +0900
+++ b/agent/src/heapstats-engines/logMain.cpp	Tue Dec 13 12:20:11 2016 +0900
@@ -76,16 +76,17 @@
  *                     e.g. ResourceExhausted, Signal or Interval.
  * \param nowTime [in] Mili-second elapsed from 1970/1/1 0:00:00.<br>
  *                     This value express time of call log function.
+ * \param description [in] Description of the event.
  * \return Value is true, if process is succeed.
  */
 inline bool TakeLogInfo(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause,
-                        TMSecTime nowTime) {
+                        TMSecTime nowTime, const char *description) {
   /* Count working time. */
   static const char *label = "Take LogInfo";
   TElapsedTimer elapsedTime(label);
 
   /* Collect log. */
-  return (logManager->collectLog(jvmti, env, cause, nowTime) == 0);
+  return (logManager->collectLog(jvmti, env, cause, nowTime, description) == 0);
 }
 
 /*!
@@ -97,7 +98,8 @@
  */
 void intervalLogProc(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause) {
   /* Call collect log by interval. */
-  if (unlikely(!TakeLogInfo(jvmti, env, cause, (TMSecTime)getNowTimeSec()))) {
+  if (unlikely(!TakeLogInfo(jvmti, env, cause,
+                            (TMSecTime)getNowTimeSec(), ""))) {
     logger->printWarnMsg("Failure interval collect log.");
   }
 }
@@ -137,7 +139,7 @@
     TMSecTime nowTime = (TMSecTime)getNowTimeSec();
     flagLogSignal = 0;
 
-    if (unlikely(!TakeLogInfo(jvmti, env, Signal, nowTime))) {
+    if (unlikely(!TakeLogInfo(jvmti, env, Signal, nowTime, ""))) {
       logger->printWarnMsg("Failure collect log by normal log signal.");
     }
   }
@@ -147,7 +149,7 @@
     TMSecTime nowTime = (TMSecTime)getNowTimeSec();
     flagAllLogSignal = 0;
 
-    if (unlikely(!TakeLogInfo(jvmti, env, AnotherSignal, nowTime))) {
+    if (unlikely(!TakeLogInfo(jvmti, env, AnotherSignal, nowTime, ""))) {
       logger->printWarnMsg("Failure collect log by all log signal.");
     }
   }
@@ -165,7 +167,7 @@
   TMSecTime occurTime = TDeadlockFinder::getInstance()->getDeadlockTime();
 
   /* Collect log. */
-  if (unlikely(!TakeLogInfo(jvmti, env, cause, occurTime))) {
+  if (unlikely(!TakeLogInfo(jvmti, env, cause, occurTime, ""))) {
     logger->printWarnMsg("Failure collect log on occurred deadlock.");
   }
 
@@ -258,7 +260,7 @@
     }
 
     /* Collect log. */
-    if (unlikely(!TakeLogInfo(jvmti, env, cause, nowTime))) {
+    if (unlikely(!TakeLogInfo(jvmti, env, cause, nowTime, description))) {
       logger->printWarnMsg("Failure collect log on resource exhausted.");
     }
   }
--- a/agent/src/heapstats-engines/logManager.cpp	Tue Dec 13 12:19:12 2016 +0900
+++ b/agent/src/heapstats-engines/logManager.cpp	Tue Dec 13 12:20:11 2016 +0900
@@ -1,7 +1,7 @@
 /*!
  * \file logManager.cpp
  * \brief This file is used collect log information.
- * Copyright (C) 2011-2015 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2016 Nippon Telegraph and Telephone Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -161,11 +161,12 @@
  * \param cause   [in] Invoke function cause.<br>
  *                     E.g. ResourceExhausted, Signal, Interval.
  * \param nowTime [in] Log collect time.
+ * \param description [in] Description of the event.
  * \return Value is zero, if process is succeed.<br />
  *         Value is error number a.k.a. "errno", if process is failure.
  */
 int TLogManager::collectLog(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause,
-                            TMSecTime nowTime) {
+                            TMSecTime nowTime, const char *description) {
   int result = 0;
   /* Variable store archive file path. */
   char arcPath[PATH_MAX] = {0};
@@ -178,7 +179,8 @@
     case OccurredDeadlock: {
       /* Collect log about java running environment and etc.. */
       int returnCode =
-          collectAllLog(jvmti, env, cause, nowTime, (char *)arcPath, PATH_MAX);
+          collectAllLog(jvmti, env, cause, nowTime,
+                        (char *)arcPath, PATH_MAX, description);
       if (unlikely(returnCode != 0)) {
         /* Check and show disk full error. */
         result = returnCode;
@@ -294,12 +296,13 @@
  * \param nowTime     [in]  Log collect time.
  * \param archivePath [out] Archive file path.
  * \param pathLen     [in]  Max size of paramter"archivePath".
+ * \param description [in] Description of the event.
  * \return Value is zero, if process is succeed.<br />
  *         Value is error number a.k.a. "errno", if process is failure.
  */
 int TLogManager::collectAllLog(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause,
                                TMSecTime nowTime, char *archivePath,
-                               size_t pathLen) {
+                               size_t pathLen, const char *description) {
   /* Variable for process result. */
   int result = 0;
   /* Working directory path. */
@@ -316,7 +319,7 @@
 
   try {
     /* Create enviroment report file. */
-    result = makeEnvironFile(basePath, cause, nowTime);
+    result = makeEnvironFile(basePath, cause, nowTime, description);
     if (unlikely(result != 0)) {
       logger->printWarnMsg("Failure create enviroment file.");
 
@@ -456,11 +459,12 @@
  * \param cause    [in] Invoke function cause.<br>
  *                      E.g. Signal, ResourceExhausted, Interval.
  * \param nowTime  [in] Log collect time.
+ * \param description [in] Description of the event.
  * \return Value is zero, if process is succeed.<br />
  *         Value is error number a.k.a. "errno", if process is failure.
  */
 int TLogManager::makeEnvironFile(char *basePath, TInvokeCause cause,
-                                 TMSecTime nowTime) {
+                                 TMSecTime nowTime, const char *description) {
   int raisedErrNum = 0;
 
   /* Invoke OS version function. */
@@ -512,6 +516,7 @@
     } envColumnList[] = {
           {"CollectionDate", "%lld", nowTime, NULL, false},
           {"LogTrigger", "%d", (TMSecTime)logCauseToInt(cause), NULL, false},
+          {"Description", "%s", 0, description, true},
           {"VmVersion", "%s", 0, jvmInfo->getVmVersion(), true},
           {"OsRelease", "%s", 0, uInfo.release, true},
           {"LibCVersion", "%s", 0, glibcVersion, true},
--- a/agent/src/heapstats-engines/logManager.hpp	Tue Dec 13 12:19:12 2016 +0900
+++ b/agent/src/heapstats-engines/logManager.hpp	Tue Dec 13 12:20:11 2016 +0900
@@ -1,7 +1,7 @@
 /*!
  * \file logManager.hpp
  * \brief This file is used collect log information.
- * Copyright (C) 2011-2015 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2016 Nippon Telegraph and Telephone Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -69,11 +69,12 @@
    * \param cause   [in] Invoke function cause.<br>
    *                     E.g. ResourceExhausted, Signal, Interval.
    * \param nowTime [in] Log collect time.
+   * \param description [in] Description of the event.
    * \return Value is zero, if process is succeed.<br />
    *         Value is error number a.k.a. "errno", if process is failure.
    */
   int collectLog(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause,
-                 TMSecTime nowTime);
+                 TMSecTime nowTime, const char *description);
 
  protected:
   /*!
@@ -97,12 +98,13 @@
    * \param nowTime     [in]  Log collect time.
    * \param archivePath [out] Archive file path.
    * \param pathLen     [in]  Max size of paramter"archivePath".
+   * \param description [in] Description of the event.
    * \return Value is zero, if process is succeed.<br />
    *         Value is error number a.k.a. "errno", if process is failure.
    */
   virtual int collectAllLog(jvmtiEnv *jvmti, JNIEnv *env, TInvokeCause cause,
                             TMSecTime nowTime, char *archivePath,
-                            size_t pathLen);
+                            size_t pathLen, const char *description);
 
   RELEASE_ONLY(private :)
 
@@ -112,11 +114,12 @@
    * \param cause    [in] Invoke function cause.<br>
    *                      E.g. Signal, ResourceExhausted, Interval.
    * \param nowTime  [in] Log collect time.
+   * \param description [in] Description of the event.
    * \return Value is zero, if process is succeed.<br />
    *         Value is error number a.k.a. "errno", if process is failure.
    */
   virtual int makeEnvironFile(char *basePath, TInvokeCause cause,
-                              TMSecTime nowTime);
+                              TMSecTime nowTime, const char *description);
 
   /*!
    * \brief Dump thread and stack information to stream.