Permalink
Browse files

initial work on diagnostics

  • Loading branch information...
1 parent 9c71f59 commit 6ddd3665ad424b999b52c533bcb645e2e922434e @jjallaire jjallaire committed Sep 26, 2012
View
@@ -38,12 +38,16 @@ if (NOT RSTUDIO_SESSION_WIN64)
\"${CMAKE_CURRENT_BINARY_DIR}/SOURCE\")
")
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/VERSION.in
+ ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
+
# install root docs
install(FILES README.md
INSTALL
COPYING
NOTICE
${CMAKE_CURRENT_BINARY_DIR}/SOURCE
+ ${CMAKE_CURRENT_BINARY_DIR}/VERSION
DESTINATION ${RSTUDIO_INSTALL_SUPPORTING})
endif()
View
@@ -0,0 +1 @@
+${CPACK_PACKAGE_VERSION}
View
@@ -157,6 +157,9 @@ if(RSTUDIO_CONFIG_CORE_DEV)
else()
+ # diagnostics
+ add_subdirectory(diagnostics)
+
# find LibR
if(RSTUDIO_SESSION_WIN64)
set(LIBR_FIND_WINDOWS_64BIT TRUE)
@@ -28,6 +28,9 @@ using namespace core;
namespace desktop {
+
+// NOTE: this code is duplicated in diagnostics as well (and also in
+// SessionOptions.hpp although the code path isn't exactly the same)
FilePath userLogPath()
{
FilePath userHomePath = core::system::userHomePath("R_USER|HOME");
@@ -0,0 +1,67 @@
+#
+# CMakeLists.txt
+#
+# Copyright (C) 2009-11 by RStudio, Inc.
+#
+# This program is licensed to you under the terms of version 3 of the
+# GNU Affero General Public License. This program is distributed WITHOUT
+# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+#
+#
+
+project(DIAGNOSTICS)
+
+# include files
+file(GLOB_RECURSE DIAGNOSTICS_HEADER_FILES "*.h*")
+
+# set include directories
+include_directories(
+ ${CORE_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+set(DIAGNOSTICS_SOURCE_FILES
+ DiagnosticsMain.cpp
+)
+
+# config file
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+if(WIN32)
+ # configure diagnostics.rc
+ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/diagnostics.rc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/diagnostics.rc)
+
+
+ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/diagnostics.exe.manifest
+ ${CMAKE_CURRENT_BINARY_DIR}/diagnostics.exe.manifest COPYONLY)
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/res.o"
+ COMMAND windres.exe
+ -I "."
+ -i "diagnostics.rc"
+ -o "${CMAKE_CURRENT_BINARY_DIR}/res.o"
+ -Ocoff
+ DEPENDS
+ "${CMAKE_CURRENT_BINARY_DIR}/diagnostics.rc"
+ "${CMAKE_CURRENT_SOURCE_DIR}/diagnostics.exe.manifest")
+ set(DIAGNOSTICS_SOURCE_FILES
+ ${DIAGNOSTICS_SOURCE_FILES}
+ "${CMAKE_CURRENT_BINARY_DIR}/res.o")
+endif()
+
+add_executable(diagnostics
+ ${DIAGNOSTICS_SOURCE_FILES}
+)
+
+# set link dependencies
+target_link_libraries(diagnostics
+ rstudio-core
+)
+if(NOT RSTUDIO_SESSION_WIN64)
+ install(TARGETS diagnostics DESTINATION ${RSTUDIO_INSTALL_BIN})
+endif()
@@ -0,0 +1,93 @@
+/*
+ * DiagnosticsMain.cpp
+ *
+ * Copyright (C) 2009-12 by RStudio, Inc.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <boost/algorithm/string.hpp>
+
+#include <core/Error.hpp>
+#include <core/Log.hpp>
+#include <core/FilePath.hpp>
+#include <core/FileSerializer.hpp>
+#include <core/system/System.hpp>
+
+#include "config.h"
+
+using namespace core;
+
+namespace {
+
+FilePath homePath()
+{
+ return core::system::userHomePath("R_USER|HOME");
+}
+
+// NOTE: this code is duplicated in diagnostics as well (and also in
+// SessionOptions.hpp although the code path isn't exactly the same)
+FilePath userLogPath()
+{
+ FilePath logPath = core::system::userSettingsPath(
+ homePath(),
+#ifdef RSTUDIO_SERVER
+ "RStudio"
+#else
+ "RStudio-Desktop"
+#endif
+ ).childPath("log");
+ return logPath;
+}
+
+void writeLogFile(const std::string& logFileName, std::ostream& ostr)
+{
+ ostr << "Log file: " << logFileName << std::endl;
+ ostr << "--------------------------------------------------" << std::endl;
+ ostr << std::endl;
+
+ FilePath logFilePath = userLogPath().childPath(logFileName);
+ if (logFilePath.exists())
+ {
+ std::string contents;
+ Error error = core::readStringFromFile(logFilePath, &contents);
+ if (error)
+ LOG_ERROR(error);
+ if (contents.empty())
+ ostr << "(Empty)" << std::endl << std::endl;
+ else
+ ostr << contents << std::endl;
+ }
+ else
+ {
+ ostr << "(Not Found)" << std::endl << std::endl;
+ }
+}
+
+
+} // anonymous namespace
+
+
+int main(int argc, char** argv)
+{
+ core::system::initializeStderrLog("rstudio-diagnostics",
+ core::system::kLogLevelWarning);
+
+ // ignore SIGPIPE
+ Error error = core::system::ignoreSignal(core::system::SigPipe);
+ if (error)
+ LOG_ERROR(error);
+
+ writeLogFile("rdesktop.log", std::cout);
+ writeLogFile("rsession-" + core::system::username() + ".log", std::cout);
+
+ return EXIT_SUCCESS;
+}
@@ -0,0 +1,14 @@
+/*
+ * config.h.in
+ *
+ * Copyright (C) 2009-12 by RStudio, Inc.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+
+#cmakedefine RSTUDIO_SERVER
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity version="1.0.0.0"
+ name="diagnostics"
+ type="win32"/>
+ <description>diagnostics</description>
+ <!-- Identify the application security requirements. -->
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <!--The ID below indicates application support for Windows Vista -->
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
+ <!--The ID below indicates application support for Windows 7 -->
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
+ </application>
+ </compatibility>
+</assembly>
@@ -0,0 +1,29 @@
+#include "winuser.h"
+
+1 RT_MANIFEST "diagnostics.exe.manifest"
+1 VERSIONINFO
+FILEVERSION ${CPACK_PACKAGE_VERSION_MAJOR},${CPACK_PACKAGE_VERSION_MINOR},${CPACK_PACKAGE_VERSION_PATCH},0
+PRODUCTVERSION ${CPACK_PACKAGE_VERSION_MAJOR},${CPACK_PACKAGE_VERSION_MINOR},${CPACK_PACKAGE_VERSION_PATCH},0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904E4"
+ BEGIN
+ VALUE "CompanyName", "RStudio, Inc.\0"
+ VALUE "FileDescription", "RStudio Diagnostics\0"
+ VALUE "FileVersion", "${CPACK_PACKAGE_VERSION_MAJOR},${CPACK_PACKAGE_VERSION_MINOR},${CPACK_PACKAGE_VERSION_PATCH},0\0"
+ VALUE "InternalName", "diagnostics\0"
+ VALUE "LegalCopyright", "Copyright (C) 2009-11 by RStudio, Inc.\0"
+ VALUE "LegalTrademarks", "RStudio (TM) is a trademark of RStudio, Inc.\0"
+ VALUE "OriginalFilename", "diagnostics.exe\0"
+ VALUE "ProductName", "RStudio\0"
+ VALUE "ProductVersion", "${CPACK_PACKAGE_VERSION_MAJOR},${CPACK_PACKAGE_VERSION_MINOR},${CPACK_PACKAGE_VERSION_PATCH},0\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
+
+
View
@@ -0,0 +1,73 @@
+#
+# Diagnostics.R
+#
+# Copyright (C) 2009-12 by RStudio, Inc.
+#
+# This program is licensed to you under the terms of version 3 of the
+# GNU Affero General Public License. This program is distributed WITHOUT
+# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+#
+#
+
+# capture output into a file
+require(utils)
+diagnosticsFile <- normalizePath(paste("~/rstudio-diagnostics-",
+ Sys.Date(),
+ ".txt",
+ sep=""),
+ mustWork = FALSE)
+
+capture.output({
+
+ # version
+ versionFile <- "../VERSION"
+ if (file.exists(versionFile)) {
+ print(readLines(versionFile))
+ cat("\n")
+ }
+
+ # basic info
+ print(as.list(Sys.which(c("R",
+ "pdflatex",
+ "bibtex",
+ "gcc",
+ "git",
+ "svn"))))
+ print(sessionInfo())
+ cat("\nSysInfo:\n")
+ print(Sys.info())
+ cat("\nR Version:\n")
+ print(version)
+ print(as.list(Sys.getenv()))
+ print(search())
+
+ cat("\nCapabilities:\n\n")
+ print(as.list(capabilities(c("png"))))
+ cat("\n")
+
+ # locate diagonstics binary and run it
+ sysName <- Sys.info()[['sysname']]
+ ext <- ifelse(identical(sysName, "Windows"), ".exe", "")
+
+ # first look for debug version
+ cppDiag <- paste("../../../qtcreator-build/diagnostics/diagnostics",
+ ext, sep="")
+ if (!file.exists(cppDiag)) {
+ if (identical(sysName, "Darwin"))
+ cppDiag <- "../../MacOS/diagnostics"
+ else
+ cppDiag <- paste("../bin/diagnostics", ext, sep="")
+ }
+
+ if (file.exists(cppDiag))
+ diag <- system(cppDiag, intern=TRUE)
+ cat(diag, sep="\n")
+
+
+}, file=diagnosticsFile)
+
+cat("Diagnostics written to:", diagnosticsFile, "\n")
+
+
View
@@ -0,0 +1 @@
+${CPACK_PACKAGE_VERSION}

0 comments on commit 6ddd366

Please sign in to comment.