Browse Source

Improve compiler/platform/libs information in logs

Add and use usedCompilerAndPlatform().  This adds compiler information to
INFO logs and the --version output, and may be helpful when trying to
diagnose/reproduce user-reported problems.

Also make INFO logs include usedLibs() output.

Closes #235
Nils Maier 11 years ago
parent
commit
2b02fac2d5
5 changed files with 154 additions and 6 deletions
  1. 3 0
      configure.ac
  2. 4 1
      src/Context.cc
  3. 137 5
      src/FeatureConfig.cc
  4. 6 0
      src/FeatureConfig.h
  5. 4 0
      src/version_usage.cc

+ 3 - 0
configure.ac

@@ -35,6 +35,8 @@ case "$host" in
     ;;
 esac
 
+AC_DEFINE_UNQUOTED([BUILD], ["$build"], [Define build-type])
+AC_DEFINE_UNQUOTED([HOST], ["$host"], [Define build-type])
 AC_DEFINE_UNQUOTED([TARGET], ["$target"], [Define target-type])
 
 # Checks for arguments.
@@ -654,6 +656,7 @@ AC_CHECK_HEADERS([argz.h \
                   sys/time.h \
                   sys/types.h \
                   sys/uio.h \
+                  sys/utsname.h \
                   termios.h \
                   unistd.h \
                   utime.h \

+ 4 - 1
src/Context.cc

@@ -174,7 +174,10 @@ Context::Context(bool standalone,
   A2_LOG_INFO("<<--- --- --- ---");
   A2_LOG_INFO("  --- --- --- ---");
   A2_LOG_INFO("  --- --- --- --->>");
-  A2_LOG_INFO(fmt("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET));
+  A2_LOG_INFO(fmt("%s %s", PACKAGE, PACKAGE_VERSION));
+  A2_LOG_INFO(usedCompilerAndPlatform());
+  A2_LOG_INFO(getOperatingSystemInfo());
+  A2_LOG_INFO(usedLibs());
   A2_LOG_INFO(MSG_LOGGING_STARTED);
 
   if(op->getAsBool(PREF_DISABLE_IPV6)) {

+ 137 - 5
src/FeatureConfig.cc

@@ -34,6 +34,9 @@
 /* copyright --> */
 #include "FeatureConfig.h"
 
+#include <sstream>
+#include <cstring>
+
 #ifdef HAVE_ZLIB
 # include <zlib.h>
 #endif // HAVE_ZLIB
@@ -61,6 +64,9 @@
 #ifdef HAVE_LIBCARES
 # include <ares.h>
 #endif // HAVE_LIBCARES
+#ifdef HAVE_SYS_UTSNAME_H
+# include <sys/utsname.h>
+#endif // HAVE_SYS_UTSNAME_H
 
 #include "util.h"
 
@@ -112,7 +118,7 @@ const char* strSupportedFeature(int feature)
 #ifdef ENABLE_BITTORRENT
     return "BitTorrent";
 #else // !ENABLE_BITTORRENT
-    return 0;
+    return nullptr;
 #endif // !ENABLE_BITTORRENT
     break;
 
@@ -128,7 +134,7 @@ const char* strSupportedFeature(int feature)
 #ifdef HAVE_ZLIB
     return "GZip";
 #else // !HAVE_ZLIB
-    return 0;
+    return nullptr;
 #endif // !HAVE_ZLIB
     break;
 
@@ -136,7 +142,7 @@ const char* strSupportedFeature(int feature)
 #ifdef ENABLE_SSL
     return "HTTPS";
 #else // !ENABLE_SSL
-    return 0;
+    return nullptr;
 #endif // !ENABLE_SSL
     break;
 
@@ -148,7 +154,7 @@ const char* strSupportedFeature(int feature)
 #ifdef ENABLE_METALINK
     return "Metalink";
 #else // !ENABLE_METALINK
-    return 0;
+    return nullptr;
 #endif // !ENABLE_METALINK
     break;
 
@@ -156,7 +162,7 @@ const char* strSupportedFeature(int feature)
 #ifdef ENABLE_XML_RPC
     return "XML-RPC";
 #else // !ENABLE_XML_RPC
-    return 0;
+    return nullptr;
 #endif // !ENABLE_XML_RPC
     break;
 
@@ -221,4 +227,130 @@ std::string usedLibs()
   return res;
 }
 
+std::string usedCompilerAndPlatform()
+{
+  std::stringstream rv;
+#if defined(__clang_version__)
+
+#ifdef __apple_build_version__
+  rv << "Apple LLVM ";
+#else // !__apple_build_version__
+  rv << "clang ";
+#endif // !__apple_build_version__
+  rv << __clang_version__;
+
+#elif defined(__INTEL_COMPILER)
+
+  rv << "Intel ICC " << __VERSION__;
+
+#elif defined( __MINGW64_VERSION_STR)
+
+  rv << "mingw-w64 " << __MINGW64_VERSION_STR;
+#ifdef __MINGW64_VERSION_STATE
+  rv << " (" << __MINGW64_VERSION_STATE << ")";
+#endif // __MINGW64_VERSION_STATE
+  rv << " / gcc " << __VERSION__;
+
+#elif defined(__GNUG__)
+
+#ifdef __MINGW32__
+  rv << "mingw ";
+#ifdef __MINGW32_MAJOR_VERSION
+  rv << (int)__MINGW32_MAJOR_VERSION;
+#endif // __MINGW32_MAJOR_VERSION
+#ifdef __MINGW32_MINOR_VERSION
+  rv << "." << (int)__MINGW32_MINOR_VERSION;
+#endif // __MINGW32_MINOR_VERSION
+  rv << " / ";
+#endif // __MINGW32__
+  rv << "gcc " << __VERSION__;
+
+#else // !defined(__GNUG__)
+
+  rv << "Unknown compiler/platform";
+
+#endif // !defined(__GNUG__)
+
+  rv << "\n  built by   " << BUILD;
+  if(strcmp(BUILD, TARGET)) {
+    rv << "\n  targetting " << TARGET;
+  }
+  rv << "\n  on         " << __DATE__ << " " << __TIME__;
+
+  return rv.str();
+}
+
+std::string getOperatingSystemInfo()
+{
+#ifdef _WIN32
+  std::stringstream rv;
+  rv << "Windows ";
+  OSVERSIONINFOEX ovi = {
+    sizeof(OSVERSIONINFOEX)
+  };
+  if(!GetVersionEx((LPOSVERSIONINFO)&ovi)) {
+    rv << "Unknown";
+    return rv.str();
+  }
+  if(ovi.dwMajorVersion < 6) {
+    rv << "Legcacy, probably XP";
+    return rv.str();
+  }
+  switch(ovi.dwMinorVersion) {
+  case 0:
+    if(ovi.wProductType == VER_NT_WORKSTATION) {
+      rv << "Vista";
+    }
+    else {
+      rv << "Server 2008";
+    }
+    break;
+
+  case 1:
+    if(ovi.wProductType == VER_NT_WORKSTATION) {
+      rv << "7";
+    }
+    else {
+      rv << "Server 2008 R2";
+    }
+    break;
+
+  default:
+    // Windows above 6.2 does not actually say so. :p
+
+    rv << ovi.dwMajorVersion;
+    if(ovi.dwMinorVersion) {
+      rv << "." << ovi.dwMinorVersion;
+    }
+    if(ovi.wProductType != VER_NT_WORKSTATION) {
+      rv << " Server";
+    }
+    break;
+  }
+  if(ovi.szCSDVersion[0]) {
+    rv << " (" << ovi.szCSDVersion << ")";
+  }
+#ifdef _WIN64
+  rv << " (x86_64)";
+#endif // _WIN64
+  return rv.str();
+#else //! _WIN32
+#ifdef HAVE_SYS_UTSNAME_H
+  struct utsname name;
+  if(!uname(&name)) {
+    if(!strstr(name.version, name.sysname) ||
+       !strstr(name.version, name.release) ||
+       !strstr(name.version, name.machine)) {
+      std::stringstream ss;
+      ss << name.sysname << " " << name.release << " " << name.version <<
+        " " << name.machine;
+      return ss.str();
+    }
+    return name.version;
+  }
+#endif // HAVE_SYS_UTSNAME_H
+  return "Unknown system";
+#endif // !_WIN32
+}
+
 } // namespace aria2

+ 6 - 0
src/FeatureConfig.h

@@ -67,6 +67,12 @@ const char* strSupportedFeature(int feature);
 // aria2.
 std::string usedLibs();
 
+// Returns a summary string of the used compiler/platform.
+std::string usedCompilerAndPlatform();
+
+// Returns the system information about the OS this binary is running on.
+std::string getOperatingSystemInfo();
+
 } // namespace aria2
 
 #endif // D_FEATURE_CONFIG_H

+ 4 - 0
src/version_usage.cc

@@ -72,6 +72,10 @@ void showVersion() {
             << MessageDigest::getSupportedHashTypeString() << "\n"
             << _("Libraries") << ": "
             << usedLibs() << "\n"
+            << _("Compiler") << ": "
+            << usedCompilerAndPlatform() << "\n"
+            << _("System") << ": "
+            << getOperatingSystemInfo() << "\n"
             << "\n"
             << fmt(_("Report bugs to %s"), PACKAGE_BUGREPORT) << "\n"
             << _("Visit") << " " << PACKAGE_URL << std::endl;