8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
Reviewed-by: rehn, iklam, kbarrett
This commit is contained in:
parent
ce9242dc85
commit
b28f905e05
@ -37,6 +37,7 @@
|
|||||||
#include "logging/logOutput.hpp"
|
#include "logging/logOutput.hpp"
|
||||||
#include "logging/logTagLevelExpression.hpp"
|
#include "logging/logTagLevelExpression.hpp"
|
||||||
#include "logging/logTagSet.hpp"
|
#include "logging/logTagSet.hpp"
|
||||||
|
#include "logging/logTagSetDescriptions.hpp"
|
||||||
#include "logging/logStream.inline.hpp"
|
#include "logging/logStream.inline.hpp"
|
||||||
#include "memory/resourceArea.hpp"
|
#include "memory/resourceArea.hpp"
|
||||||
|
|
||||||
@ -1174,4 +1175,28 @@ void Test_invalid_log_file() {
|
|||||||
remove(target_name);
|
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
|
#endif // PRODUCT
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "logging/logDiagnosticCommand.hpp"
|
#include "logging/logDiagnosticCommand.hpp"
|
||||||
#include "logging/logFileOutput.hpp"
|
#include "logging/logFileOutput.hpp"
|
||||||
#include "logging/logOutput.hpp"
|
#include "logging/logOutput.hpp"
|
||||||
|
#include "logging/logStream.hpp"
|
||||||
#include "logging/logTagLevelExpression.hpp"
|
#include "logging/logTagLevelExpression.hpp"
|
||||||
#include "logging/logTagSet.hpp"
|
#include "logging/logTagSet.hpp"
|
||||||
#include "memory/allocation.inline.hpp"
|
#include "memory/allocation.inline.hpp"
|
||||||
@ -75,11 +76,17 @@ bool ConfigurationLock::current_thread_has_lock() {
|
|||||||
void LogConfiguration::post_initialize() {
|
void LogConfiguration::post_initialize() {
|
||||||
LogDiagnosticCommand::registerCommand();
|
LogDiagnosticCommand::registerCommand();
|
||||||
Log(logging) log;
|
Log(logging) log;
|
||||||
log.info("Log configuration fully initialized.");
|
if (log.is_info()) {
|
||||||
log_develop_info(logging)("Develop logging is available.");
|
log.info("Log configuration fully initialized.");
|
||||||
if (log.is_trace()) {
|
log_develop_info(logging)("Develop logging is available.");
|
||||||
ResourceMark rm;
|
if (log.is_debug()) {
|
||||||
describe(log.trace_stream());
|
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 @@ void LogConfiguration::describe_available(outputStream* out){
|
|||||||
}
|
}
|
||||||
out->cr();
|
out->cr();
|
||||||
|
|
||||||
|
LogTagSet::describe_tagsets(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogConfiguration::describe_current_configuration(outputStream* out){
|
void LogConfiguration::describe_current_configuration(outputStream* out){
|
||||||
@ -449,7 +457,10 @@ void LogConfiguration::print_command_line_help(FILE* out) {
|
|||||||
}
|
}
|
||||||
jio_fprintf(out, "\n Specifying 'all' instead of a tag combination matches all tag combinations.\n\n");
|
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"
|
" 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"
|
" Specifying %%p and/or %%t in the filename will expand to the JVM's PID and startup timestamp, respectively.\n\n"
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
#include "logging/logOutput.hpp"
|
#include "logging/logOutput.hpp"
|
||||||
#include "logging/logTag.hpp"
|
#include "logging/logTag.hpp"
|
||||||
#include "logging/logTagSet.hpp"
|
#include "logging/logTagSet.hpp"
|
||||||
|
#include "logging/logTagSetDescriptions.hpp"
|
||||||
#include "memory/allocation.inline.hpp"
|
#include "memory/allocation.inline.hpp"
|
||||||
|
#include "utilities/ostream.hpp"
|
||||||
|
|
||||||
LogTagSet* LogTagSet::_list = NULL;
|
LogTagSet* LogTagSet::_list = NULL;
|
||||||
size_t LogTagSet::_ntagsets = 0;
|
size_t LogTagSet::_ntagsets = 0;
|
||||||
@ -127,3 +129,44 @@ void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
|
|||||||
}
|
}
|
||||||
va_end(saved_args);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -39,17 +39,17 @@ class LogMessageBuffer;
|
|||||||
class LogTagSet VALUE_OBJ_CLASS_SPEC {
|
class LogTagSet VALUE_OBJ_CLASS_SPEC {
|
||||||
private:
|
private:
|
||||||
static LogTagSet* _list;
|
static LogTagSet* _list;
|
||||||
static size_t _ntagsets;
|
static size_t _ntagsets;
|
||||||
|
|
||||||
LogTagSet* const _next;
|
LogTagSet* const _next;
|
||||||
size_t _ntags;
|
size_t _ntags;
|
||||||
LogTagType _tag[LogTag::MaxTags];
|
LogTagType _tag[LogTag::MaxTags];
|
||||||
|
|
||||||
LogOutputList _output_list;
|
LogOutputList _output_list;
|
||||||
LogDecorators _decorators;
|
LogDecorators _decorators;
|
||||||
|
|
||||||
typedef size_t (*PrefixWriter)(char* buf, size_t size);
|
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.
|
// Keep constructor private to prevent incorrect instantiations of this class.
|
||||||
// Only LogTagSetMappings can create/contain instances of this class.
|
// Only LogTagSetMappings can create/contain instances of this class.
|
||||||
@ -62,6 +62,9 @@ class LogTagSet VALUE_OBJ_CLASS_SPEC {
|
|||||||
friend class LogTagSetMapping;
|
friend class LogTagSetMapping;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void describe_tagsets(outputStream* out);
|
||||||
|
static void list_all_tagsets(outputStream* out);
|
||||||
|
|
||||||
static LogTagSet* first() {
|
static LogTagSet* first() {
|
||||||
return _list;
|
return _list;
|
||||||
}
|
}
|
||||||
|
42
hotspot/src/share/vm/logging/logTagSetDescriptions.cpp
Normal file
42
hotspot/src/share/vm/logging/logTagSetDescriptions.cpp
Normal file
@ -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 }
|
||||||
|
};
|
36
hotspot/src/share/vm/logging/logTagSetDescriptions.hpp
Normal file
36
hotspot/src/share/vm/logging/logTagSetDescriptions.hpp
Normal file
@ -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
|
@ -78,6 +78,7 @@ void InternalVMTests::run() {
|
|||||||
run_unit_test(Test_log_prefix);
|
run_unit_test(Test_log_prefix);
|
||||||
run_unit_test(Test_log_big);
|
run_unit_test(Test_log_big);
|
||||||
run_unit_test(Test_logtagset_duplicates);
|
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_rotation);
|
||||||
run_unit_test(Test_log_file_startup_truncation);
|
run_unit_test(Test_log_file_startup_truncation);
|
||||||
run_unit_test(Test_invalid_log_file);
|
run_unit_test(Test_invalid_log_file);
|
||||||
|
Loading…
Reference in New Issue
Block a user