Skip to content

Commit

Permalink
initial work on diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Sep 26, 2012
1 parent 9c71f59 commit 6ddd366
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions VERSION.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${CPACK_PACKAGE_VERSION}
3 changes: 3 additions & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/desktop/DesktopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
67 changes: 67 additions & 0 deletions src/cpp/diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
93 changes: 93 additions & 0 deletions src/cpp/diagnostics/DiagnosticsMain.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions src/cpp/diagnostics/config.h.in
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions src/cpp/diagnostics/diagnostics.exe.manifest
Original file line number Diff line number Diff line change
@@ -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>
29 changes: 29 additions & 0 deletions src/cpp/diagnostics/diagnostics.rc.in
Original file line number Diff line number Diff line change
@@ -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


73 changes: 73 additions & 0 deletions src/cpp/r/R/Diagnostics.R
Original file line number Diff line number Diff line change
@@ -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")


1 change: 1 addition & 0 deletions src/cpp/r/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${CPACK_PACKAGE_VERSION}

0 comments on commit 6ddd366

Please sign in to comment.