Skip to content

Commit

Permalink
sentry.io integration
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Dec 20, 2022
1 parent b6f73d9 commit f3a6fb7
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 40 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
- name: Gradle
working-directory: shell/android-studio
run: ./gradlew assembleRelease --parallel
env:
SENTRY_UPLOAD_URL: ${{ secrets.SENTRY_UPLOAD_URL }}

- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -71,6 +73,24 @@ jobs:
run: aws s3 sync shell/android-studio/flycast/build/outputs/apk/release s3://flycast-builds/android/${GITHUB_REF#refs/}-$GITHUB_SHA --acl public-read --exclude='*.json' --follow-symlinks
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' }}

- name: Upload to S3 (symbols)
run: aws s3 sync symbols s3://flycast-symbols/android --follow-symlinks
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' }}
- name: Setup Sentry CLI
uses: mathieu-bour/[email protected]
env:
SENTRY_TOKEN: ${{ secrets.SENTRY_TOKEN }}
with:
url: https://sentry.io
token: ${{ env.SENTRY_TOKEN }}
organization: flycast
project: minidump
if: ${{ env.SENTRY_TOKEN != '' }}

- name: Upload symbols to Sentry
run: |
VERSION=$(git describe --tags --always)
sentry-cli releases new "$VERSION"
sentry-cli releases set-commits "$VERSION" --auto
sentry-cli upload-dif symbols
shell: bash
env:
SENTRY_TOKEN: ${{ secrets.SENTRY_TOKEN }}
if: ${{ env.SENTRY_TOKEN != '' }}
34 changes: 26 additions & 8 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ jobs:

- name: CMake
run: |
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.buildType }} -DCMAKE_INSTALL_PREFIX=artifact ${{ matrix.config.cmakeArgs }}
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.buildType }} -DCMAKE_INSTALL_PREFIX=artifact ${{ matrix.config.cmakeArgs }} -DSENTRY_UPLOAD_URL=${{ env.SENTRY_UPLOAD_URL }}
cmake --build build --config ${{ matrix.config.buildType }} --target install
env:
SENTRY_UPLOAD_URL: ${{ secrets.SENTRY_UPLOAD_URL }}

- name: Unit Tests
run: |
Expand All @@ -96,10 +98,8 @@ jobs:

- name: Dump symbols
run: |
core/deps/breakpad/bin/dump_syms artifact/bin/flycast.exe > flycast.exe.sym 2>/dev/null
BUILD_ID=`head -1 flycast.exe.sym | awk '{ print $4 }'`
mkdir -p symbols/flycast.exe/$BUILD_ID
mv flycast.exe.sym symbols/flycast.exe/$BUILD_ID
mkdir -p symbols
core/deps/breakpad/bin/dump_syms artifact/bin/flycast.exe > symbols/flycast.sym 2>/dev/null
strip artifact/bin/flycast.exe
if: matrix.config.name == 'x86_64-w64-mingw32'

Expand Down Expand Up @@ -134,7 +134,25 @@ jobs:
shell: bash
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' }}

- name: Upload symbols to S3 (Windows-MinGW, macOS)
run: aws s3 sync symbols s3://flycast-symbols/${{ matrix.config.destDir }} --follow-symlinks
- name: Setup Sentry CLI
uses: mathieu-bour/[email protected]
env:
SENTRY_TOKEN: ${{ secrets.SENTRY_TOKEN }}
with:
url: https://sentry.io
token: ${{ env.SENTRY_TOKEN }}
organization: flycast
project: minidump
if: ${{ env.SENTRY_TOKEN != '' }}

- name: Upload symbols to Sentry (Windows, macOS)
run: |
VERSION=$(git describe --tags --always)
sentry-cli releases new "$VERSION"
sentry-cli releases set-commits "$VERSION" --auto
sentry-cli upload-dif symbols
shell: bash
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' && (matrix.config.name == 'x86_64-w64-mingw32' || matrix.config.name == 'apple-darwin') }}
env:
SENTRY_TOKEN: ${{ secrets.SENTRY_TOKEN }}
if: ${{ env.SENTRY_TOKEN != '' && (matrix.config.name == 'x86_64-w64-mingw32' || matrix.config.name == 'apple-darwin') }}

23 changes: 11 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ option(USE_OPENGL "Use OpenGL API" ON)
option(USE_VIDEOCORE "RPI: use the legacy Broadcom GLES libraries" OFF)
option(APPLE_BREAKPAD "macOS: Build breakpad client and dump symbols" OFF)
option(ENABLE_GDB_SERVER "Build with GDB debugging support" OFF)
option(SENTRY_UPLOAD_URL "Sentry upload URL" "")

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/shell/cmake")

Expand Down Expand Up @@ -194,6 +195,10 @@ if(IOS)
GLES_SILENCE_DEPRECATION)
endif()

if(NOT ${SENTRY_UPLOAD_URL} STREQUAL "")
target_compile_definitions(${PROJECT_NAME} PRIVATE SENTRY_UPLOAD=${SENTRY_UPLOAD_URL})
endif()

target_include_directories(${PROJECT_NAME} PRIVATE core core/deps core/deps/stb core/khronos core/deps/json)
if(LIBRETRO)
target_include_directories(${PROJECT_NAME} PRIVATE shell/libretro)
Expand Down Expand Up @@ -258,36 +263,30 @@ if(NOT LIBRETRO)
if(${CMAKE_GENERATOR} MATCHES "^Xcode.*")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND sleep 20
COMMAND mkdir -p ../symbols
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build/breakpad/dump_syms
-a x86_64
-g ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app.dSYM
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app/Contents/MacOS/Flycast > Flycast.sym
COMMAND mkdir -p ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
COMMAND mv Flycast.sym ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app/Contents/MacOS/Flycast > ../symbols/Flycast-x64.sym
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build/breakpad/dump_syms
-a arm64
-g ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app.dSYM
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app/Contents/MacOS/Flycast > Flycast.sym
COMMAND mkdir -p ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
COMMAND mv Flycast.sym ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Flycast.app/Contents/MacOS/Flycast > ../symbols/Flycast-arm64.sym
)
else()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND sleep 20
COMMAND mkdir -p ../symbols
COMMAND dsymutil ${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/MacOS/Flycast
-o ${CMAKE_CURRENT_BINARY_DIR}/Flycast.app.dSYM
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build/breakpad/dump_syms
-a x86_64
-g ${CMAKE_CURRENT_BINARY_DIR}/Flycast.app.dSYM
${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/MacOS/Flycast > Flycast.sym
COMMAND mkdir -p ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
COMMAND mv Flycast.sym ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/MacOS/Flycast > ../symbols/Flycast-x64.sym
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build/breakpad/dump_syms
-a arm64
-g ${CMAKE_CURRENT_BINARY_DIR}/Flycast.app.dSYM
${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/MacOS/Flycast > Flycast.sym
COMMAND mkdir -p ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
COMMAND mv Flycast.sym ../symbols/Flycast/`head -1 Flycast.sym | awk '{ print $4 }'`
${CMAKE_CURRENT_BINARY_DIR}/Flycast.app/Contents/MacOS/Flycast > ../symbols/Flycast-arm64.sym
)
endif()
endif()
Expand Down
1 change: 1 addition & 0 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Option<bool> OpenGlChecks("OpenGlChecks", false, "validate");

Option<std::vector<std::string>, false> ContentPath("Dreamcast.ContentPath");
Option<bool, false> HideLegacyNaomiRoms("Dreamcast.HideLegacyNaomiRoms", true);
Option<bool> UploadCrashLogs("UploadCrashLogs", true);

// Network

Expand Down
1 change: 1 addition & 0 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ extern Option<bool> OpenGlChecks;

extern Option<std::vector<std::string>, false> ContentPath;
extern Option<bool, false> HideLegacyNaomiRoms;
extern Option<bool> UploadCrashLogs;

// Network

Expand Down
6 changes: 5 additions & 1 deletion core/linux-dist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ std::vector<std::string> find_system_data_dirs()
#if defined(USE_BREAKPAD)
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded)
{
printf("Minidump saved to '%s'\n", descriptor.path());
if (succeeded)
registerCrash(descriptor.directory(), descriptor.path());

return succeeded;
}
#endif
Expand All @@ -310,6 +312,8 @@ int main(int argc, char* argv[])
//appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
#endif
#if defined(USE_BREAKPAD)
auto async = std::async(std::launch::async, uploadCrashes, "/tmp");

google_breakpad::MinidumpDescriptor descriptor("/tmp");
google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
#endif
Expand Down
71 changes: 71 additions & 0 deletions core/oslib/oslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "stdclass.h"
#include "cfg/cfg.h"
#include "cfg/option.h"
#ifndef _WIN32
#include <unistd.h>
#endif

namespace hostfs
{
Expand Down Expand Up @@ -145,3 +148,71 @@ std::string getBiosFontPath()
}

}

#ifdef USE_BREAKPAD

#include "rend/boxart/http_client.h"
#include "version.h"

#define FLYCAST_CRASH_LIST "flycast-crashes.txt"

void registerCrash(const std::string& directory, const char *path)
{
FILE *f = nowide::fopen((directory + "/" FLYCAST_CRASH_LIST).c_str(), "at");
if (f != nullptr)
{
fprintf(f, "%s", path);
fclose(f);
}
}

void uploadCrashes(const std::string& directory)
{
FILE *f = nowide::fopen((directory + "/" FLYCAST_CRASH_LIST).c_str(), "rt");
if (f == nullptr)
return;
http::init();
char line[256];
bool uploadFailure = false;
while (fgets(line, sizeof(line), f) != nullptr)
{
char *p = line + strlen(line) - 1;
if (*p == '\n')
*p = '\0';
if (file_exists(line))
{
#ifdef SENTRY_UPLOAD
#define STRINGIZE(x) #x
if (config::UploadCrashLogs)
{
NOTICE_LOG(COMMON, "Uploading minidump %s", line);
std::vector<http::PostField> fields;
fields.emplace_back("upload_file_minidump", std::string(line), "application/octet-stream");
fields.emplace_back("flycast_version", std::string(GIT_VERSION));
// TODO log, config, gpu/driver
int rc = http::post(STRINGIZE(SENTRY_UPLOAD), fields);
if (rc >= 200 && rc < 300)
nowide::remove(line);
else
uploadFailure = true;
}
else
#undef STRINGIZE
#endif
{
nowide::remove(line);
}
}
}
http::term();
fclose(f);
if (!uploadFailure)
nowide::remove((directory + "/" FLYCAST_CRASH_LIST).c_str());
}

#else

void registerCrash(const std::string& directory, const char *path) {}
void uploadCrashes(const std::string& directory) {}

#endif
13 changes: 13 additions & 0 deletions core/oslib/oslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ u32 static inline bitscanrev(u32 v)
#endif
}

u32 static inline bitscanrev64(u64 v)
{
#ifdef __GNUC__
return 63 - __builtin_clzll(v);
#else
unsigned long rv;
_BitScanReverse64(&rv, (__int64)v);
return rv;
#endif
}

namespace hostfs
{
std::string getVmuPath(const std::string& port);
Expand Down Expand Up @@ -135,3 +146,5 @@ static inline void freeAligned(void *p)
#endif
}

void registerCrash(const std::string& directory, const char *path);
void uploadCrashes(const std::string& directory);
Loading

0 comments on commit f3a6fb7

Please sign in to comment.