8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
authormlarsson
Wed, 11 May 2016 10:54:31 +0200
changeset 38292 73a0be9b2f47
parent 38291 bf212274d2f0
child 38293 fb5f66e3011f
child 38296 a15a5e67d500
8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions Reviewed-by: rehn, iklam, kbarrett
hotspot/src/share/vm/logging/log.cpp
hotspot/src/share/vm/logging/logConfiguration.cpp
hotspot/src/share/vm/logging/logTagSet.cpp
hotspot/src/share/vm/logging/logTagSet.hpp
hotspot/src/share/vm/logging/logTagSetDescriptions.cpp
hotspot/src/share/vm/logging/logTagSetDescriptions.hpp
hotspot/src/share/vm/utilities/internalVMTests.cpp
--- a/hotspot/src/share/vm/logging/log.cpp	Wed May 11 02:32:14 2016 -0400
+++ b/hotspot/src/share/vm/logging/log.cpp	Wed May 11 10:54:31 2016 +0200
@@ -37,6 +37,7 @@
 #include "logging/logOutput.hpp"
 #include "logging/logTagLevelExpression.hpp"
 #include "logging/logTagSet.hpp"
+#include "logging/logTagSetDescriptions.hpp"
 #include "logging/logStream.inline.hpp"
 #include "memory/resourceArea.hpp"
 
@@ -1174,4 +1175,28 @@
   remove(target_name);
 }
 
+// Ensure -Xlog:help and LogConfiguration::describe contain tagset descriptions
+void Test_logtagset_descriptions() {
+  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
+    char expected[1024];
+    d->tagset->label(expected, sizeof(expected), "+");
+    jio_snprintf(expected + strlen(expected),
+                 sizeof(expected) - strlen(expected),
+                 ": %s", d->descr);
+
+    ResourceMark rm;
+    stringStream ss;
+    LogConfiguration::describe(&ss);
+    assert(strstr(ss.as_string(), expected) != NULL,
+           "missing log tag set descriptions in LogConfiguration::describe");
+
+    TestLogFile file("log_tagset_descriptions");
+    FILE* fp = fopen(file.name(), "w+");
+    assert(fp != NULL, "File open error");
+    LogConfiguration::print_command_line_help(fp);
+    fclose(fp);
+    assert(number_of_lines_with_substring_in_file(file.name(), expected) > 0,
+           "missing log tag set descriptions in -Xlog:help output");
+  }
+}
 #endif // PRODUCT
--- a/hotspot/src/share/vm/logging/logConfiguration.cpp	Wed May 11 02:32:14 2016 -0400
+++ b/hotspot/src/share/vm/logging/logConfiguration.cpp	Wed May 11 10:54:31 2016 +0200
@@ -29,6 +29,7 @@
 #include "logging/logDiagnosticCommand.hpp"
 #include "logging/logFileOutput.hpp"
 #include "logging/logOutput.hpp"
+#include "logging/logStream.hpp"
 #include "logging/logTagLevelExpression.hpp"
 #include "logging/logTagSet.hpp"
 #include "memory/allocation.inline.hpp"
@@ -75,11 +76,17 @@
 void LogConfiguration::post_initialize() {
   LogDiagnosticCommand::registerCommand();
   Log(logging) log;
-  log.info("Log configuration fully initialized.");
-  log_develop_info(logging)("Develop logging is available.");
-  if (log.is_trace()) {
-    ResourceMark rm;
-    describe(log.trace_stream());
+  if (log.is_info()) {
+    log.info("Log configuration fully initialized.");
+    log_develop_info(logging)("Develop logging is available.");
+    if (log.is_debug()) {
+      LogStream debug_stream(log.debug());
+      describe(&debug_stream);
+      if (log.is_trace()) {
+        LogStream trace_stream(log.trace());
+        LogTagSet::list_all_tagsets(&trace_stream);
+      }
+    }
   }
 }
 
@@ -402,6 +409,7 @@
   }
   out->cr();
 
+  LogTagSet::describe_tagsets(out);
 }
 
 void LogConfiguration::describe_current_configuration(outputStream* out){
@@ -449,7 +457,10 @@
   }
   jio_fprintf(out, "\n Specifying 'all' instead of a tag combination matches all tag combinations.\n\n");
 
-  jio_fprintf(out, "Available log outputs:\n"
+  fileStream stream(out, false);
+  LogTagSet::describe_tagsets(&stream);
+
+  jio_fprintf(out, "\nAvailable log outputs:\n"
               " stdout, stderr, file=<filename>\n"
               " Specifying %%p and/or %%t in the filename will expand to the JVM's PID and startup timestamp, respectively.\n\n"
 
--- a/hotspot/src/share/vm/logging/logTagSet.cpp	Wed May 11 02:32:14 2016 -0400
+++ b/hotspot/src/share/vm/logging/logTagSet.cpp	Wed May 11 10:54:31 2016 +0200
@@ -28,7 +28,9 @@
 #include "logging/logOutput.hpp"
 #include "logging/logTag.hpp"
 #include "logging/logTagSet.hpp"
+#include "logging/logTagSetDescriptions.hpp"
 #include "memory/allocation.inline.hpp"
+#include "utilities/ostream.hpp"
 
 LogTagSet*  LogTagSet::_list      = NULL;
 size_t      LogTagSet::_ntagsets  = 0;
@@ -127,3 +129,44 @@
   }
   va_end(saved_args);
 }
+
+static const size_t TagSetBufferSize = 128;
+
+void LogTagSet::describe_tagsets(outputStream* out) {
+  out->print_cr("Described tag combinations:");
+  for (const LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
+    char buf[TagSetBufferSize];
+    d->tagset->label(buf, sizeof(buf), "+");
+    out->print_cr(" %s: %s", buf, d->descr);
+  }
+}
+
+static int qsort_strcmp(const void* a, const void* b) {
+  return strcmp((*(const char**)a), (*(const char**)b));
+}
+
+void LogTagSet::list_all_tagsets(outputStream* out) {
+  char** tagset_labels = NEW_C_HEAP_ARRAY(char*, _ntagsets, mtLogging);
+
+  // Generate the list of tagset labels
+  size_t idx = 0;
+  for (LogTagSet* ts = first(); ts != NULL; ts = ts->next()) {
+    char buf[TagSetBufferSize];
+    ts->label(buf, sizeof(buf), "+");
+    tagset_labels[idx++] = os::strdup_check_oom(buf, mtLogging);
+  }
+  assert(idx == _ntagsets, "_ntagsets and list of tagsets not in sync");
+
+  // Sort them lexicographically
+  qsort(tagset_labels, _ntagsets, sizeof(*tagset_labels), qsort_strcmp);
+
+  // Print and then free the labels
+  out->print("All available tag sets: ");
+  for (idx = 0; idx < _ntagsets; idx++) {
+    out->print("%s%s", (idx == 0 ? "" : ", "), tagset_labels[idx]);
+    os::free(tagset_labels[idx]);
+  }
+  out->cr();
+  FREE_C_HEAP_ARRAY(char*, tagset_labels);
+}
+
--- a/hotspot/src/share/vm/logging/logTagSet.hpp	Wed May 11 02:32:14 2016 -0400
+++ b/hotspot/src/share/vm/logging/logTagSet.hpp	Wed May 11 10:54:31 2016 +0200
@@ -39,17 +39,17 @@
 class LogTagSet VALUE_OBJ_CLASS_SPEC {
  private:
   static LogTagSet* _list;
-  static size_t     _ntagsets;
+  static size_t _ntagsets;
 
-  LogTagSet* const  _next;
-  size_t            _ntags;
-  LogTagType        _tag[LogTag::MaxTags];
+  LogTagSet* const _next;
+  size_t _ntags;
+  LogTagType _tag[LogTag::MaxTags];
 
-  LogOutputList     _output_list;
-  LogDecorators     _decorators;
+  LogOutputList _output_list;
+  LogDecorators _decorators;
 
   typedef size_t (*PrefixWriter)(char* buf, size_t size);
-  PrefixWriter      _write_prefix;
+  PrefixWriter _write_prefix;
 
   // Keep constructor private to prevent incorrect instantiations of this class.
   // Only LogTagSetMappings can create/contain instances of this class.
@@ -62,6 +62,9 @@
   friend class LogTagSetMapping;
 
  public:
+  static void describe_tagsets(outputStream* out);
+  static void list_all_tagsets(outputStream* out);
+
   static LogTagSet* first() {
     return _list;
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/share/vm/logging/logTagSetDescriptions.cpp	Wed May 11 10:54:31 2016 +0200
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+#include "precompiled.hpp"
+#include "logging/logTag.hpp"
+#include "logging/logTagSet.hpp"
+#include "logging/logTagSetDescriptions.hpp"
+
+// List of described tag sets. Tags should be specified using the LOG_TAGS()
+// macro. Described tag sets can be listed from command line (or DCMD) using
+// -Xlog:help (or "VM.log list")
+#define LOG_TAG_SET_DESCRIPTION_LIST \
+  LOG_TAG_SET_DESCRIPTION(LOG_TAGS(logging), \
+                          "Logging for the log framework itself")
+
+#define LOG_TAG_SET_DESCRIPTION(tags, descr) \
+  { &LogTagSetMapping<tags>::tagset(), descr },
+
+struct LogTagSetDescription tagset_descriptions[] = {
+  LOG_TAG_SET_DESCRIPTION_LIST
+  { NULL, NULL }
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/share/vm/logging/logTagSetDescriptions.hpp	Wed May 11 10:54:31 2016 +0200
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+#ifndef SHARE_VM_LOGGING_LOGTAGSETDESCRIPTIONS_HPP
+#define SHARE_VM_LOGGING_LOGTAGSETDESCRIPTIONS_HPP
+
+class LogTagSet;
+
+struct LogTagSetDescription {
+  const LogTagSet* tagset;
+  const char* descr;
+};
+
+extern struct LogTagSetDescription tagset_descriptions[];
+
+#endif // SHARE_VM_LOGGING_LOGTAGSETDESCRIPTIONS_HPP
--- a/hotspot/src/share/vm/utilities/internalVMTests.cpp	Wed May 11 02:32:14 2016 -0400
+++ b/hotspot/src/share/vm/utilities/internalVMTests.cpp	Wed May 11 10:54:31 2016 +0200
@@ -78,6 +78,7 @@
   run_unit_test(Test_log_prefix);
   run_unit_test(Test_log_big);
   run_unit_test(Test_logtagset_duplicates);
+  run_unit_test(Test_logtagset_descriptions);
   run_unit_test(Test_log_file_startup_rotation);
   run_unit_test(Test_log_file_startup_truncation);
   run_unit_test(Test_invalid_log_file);