changeset 36174:481391df586b

8148219: Add decorator hostname to UL Reviewed-by: dholmes, mlarsson Contributed-by: robbin.ehn@oracle.com
author mlarsson
date Wed, 17 Feb 2016 11:11:47 +0100
parents 31a3af05892d
children fe3a8d7c73e9
files hotspot/src/os/posix/vm/os_posix.cpp hotspot/src/os/windows/vm/os_windows.cpp hotspot/src/share/vm/logging/logConfiguration.cpp hotspot/src/share/vm/logging/logDecorations.cpp hotspot/src/share/vm/logging/logDecorations.hpp hotspot/src/share/vm/logging/logDecorators.hpp hotspot/src/share/vm/runtime/os.hpp
diffstat 7 files changed, 29 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -238,14 +238,12 @@
   st->cr();
 }
 
-#ifndef PRODUCT
 bool os::get_host_name(char* buf, size_t buflen) {
   struct utsname name;
   uname(&name);
   jio_snprintf(buf, buflen, "%s", name.nodename);
   return true;
 }
-#endif // PRODUCT
 
 bool os::has_allocatable_memory_limit(julong* limit) {
   struct rlimit rlim;
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1531,12 +1531,10 @@
   return result;
 }
 
-#ifndef PRODUCT
 bool os::get_host_name(char* buf, size_t buflen) {
   DWORD size = (DWORD)buflen;
   return (GetComputerNameEx(ComputerNameDnsHostname, buf, &size) == TRUE);
 }
-#endif // PRODUCT
 
 void os::get_summary_os_info(char* buf, size_t buflen) {
   stringStream sst(buf, buflen);
--- a/hotspot/src/share/vm/logging/logConfiguration.cpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/share/vm/logging/logConfiguration.cpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -82,8 +82,7 @@
 
 void LogConfiguration::initialize(jlong vm_start_time) {
   LogFileOutput::set_file_name_parameters(vm_start_time);
-  LogDecorations::set_vm_start_time_millis(vm_start_time);
-
+  LogDecorations::initialize(vm_start_time);
   assert(_outputs == NULL, "Should not initialize _outputs before this function, initialize called twice?");
   _outputs = NEW_C_HEAP_ARRAY(LogOutput*, 2, mtLogging);
   _outputs[0] = LogOutput::Stdout;
--- a/hotspot/src/share/vm/logging/logDecorations.cpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/share/vm/logging/logDecorations.cpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -29,12 +29,21 @@
 #include "services/management.hpp"
 
 jlong LogDecorations::_vm_start_time_millis = 0;
+const char* LogDecorations::_host_name = "";
 
 LogDecorations::LogDecorations(LogLevelType level, const LogTagSet &tagset, const LogDecorators &decorators)
   : _level(level), _tagset(tagset), _millis(-1) {
   create_decorations(decorators);
 }
 
+void LogDecorations::initialize(jlong vm_start_time) {
+  char buffer[1024];
+  if (os::get_host_name(buffer, sizeof(buffer))){
+    _host_name = os::strdup_check_oom(buffer);
+  }
+  _vm_start_time_millis = vm_start_time;
+}
+
 void LogDecorations::create_decorations(const LogDecorators &decorators) {
   char* position = _decorations_buffer;
   #define DECORATOR(full_name, abbr) \
@@ -109,3 +118,9 @@
   int written = _tagset.label(pos, DecorationsBufferSize - (pos - _decorations_buffer));
   ASSERT_AND_RETURN(written, pos)
 }
+
+char* LogDecorations::create_hostname_decoration(char* pos) {
+  int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%s", _host_name);
+  ASSERT_AND_RETURN(written, pos)
+}
+
--- a/hotspot/src/share/vm/logging/logDecorations.hpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/share/vm/logging/logDecorations.hpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -39,6 +39,7 @@
   LogTagSet _tagset;
   jlong _millis;
   static jlong _vm_start_time_millis;
+  static const char* _host_name;
 
   jlong java_millis();
   void create_decorations(const LogDecorators& decorators);
@@ -48,15 +49,13 @@
 #undef DECORATOR
 
  public:
+  static void initialize(jlong vm_start_time);
+
   LogDecorations(LogLevelType level, const LogTagSet& tagset, const LogDecorators& decorators);
 
   const char* decoration(LogDecorators::Decorator decorator) const {
     return _decoration_offset[decorator];
   }
-
-  static void set_vm_start_time_millis(jlong start_time) {
-    _vm_start_time_millis = start_time;
-  }
 };
 
 #endif // SHARE_VM_LOGGING_LOGDECORATIONS_HPP
--- a/hotspot/src/share/vm/logging/logDecorators.hpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/share/vm/logging/logDecorators.hpp	Wed Feb 17 11:11:47 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -34,6 +34,7 @@
 // uptimemillis - Milliseconds since the JVM started
 // timenanos    - The same value as generated by System.nanoTime()
 // uptimenanos  - Nanoseconds since the JVM started
+// hostname     - The hostname
 // pid          - The process identifier
 // tid          - The thread identifier
 // level        - The level associated with the log message
@@ -45,6 +46,7 @@
   DECORATOR(uptimemillis, um)   \
   DECORATOR(timenanos,    tn)   \
   DECORATOR(uptimenanos,  un)   \
+  DECORATOR(hostname,     hn)   \
   DECORATOR(pid,          p)    \
   DECORATOR(tid,          ti)   \
   DECORATOR(level,        l)    \
--- a/hotspot/src/share/vm/runtime/os.hpp	Tue Feb 16 21:58:49 2016 -0500
+++ b/hotspot/src/share/vm/runtime/os.hpp	Wed Feb 17 11:11:47 2016 +0100
@@ -152,7 +152,6 @@
   static size_t page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned);
 
   // Get summary strings for system information in buffer provided
-  static bool  get_host_name(char* buf, size_t buflen) PRODUCT_RETURN_(return false;);  // true if available
   static void  get_summary_cpu_info(char* buf, size_t buflen);
   static void  get_summary_os_info(char* buf, size_t buflen);
 
@@ -595,6 +594,9 @@
   // Write to stream
   static int log_vsnprintf(char* buf, size_t len, const char* fmt, va_list args) ATTRIBUTE_PRINTF(3, 0);
 
+  // Get host name in buffer provided
+  static bool get_host_name(char* buf, size_t buflen);
+
   // Print out system information; they are called by fatal error handler.
   // Output format may be different on different platforms.
   static void print_os_info(outputStream* st);