|
| 1 | +#ifndef SENTRY_H__ |
| 2 | +#define SENTRY_H__ |
| 3 | + |
| 4 | +# Fastdup c++ source code |
| 5 | +# (c) Dr. Danny Bickson and Dr. Amir Alush. |
| 6 | +# File to collect configuration and performance in case of crash using sentry |
| 7 | +# For debugging the crash we collect the current config (for example run_mode, feature vector length etc.) |
| 8 | +# There is no perfosnal or identifiable information collected. |
| 9 | + |
| 10 | +#include <string> |
| 11 | +#ifndef APPLE |
| 12 | +#include <sentry.h> |
| 13 | +#endif //APPLE |
| 14 | +#include "definitions.h" |
| 15 | +#include "performance.h" |
| 16 | + |
| 17 | +using namespace std; |
| 18 | +void fastdup_sentry_init(void) { |
| 19 | + |
| 20 | + //run_sentry can be turned of eitehr by turi_param='run_sentry=0' or by defining an env variable SENTRY_OPT_OUT |
| 21 | + if (run_sentry == 0) |
| 22 | + return; |
| 23 | + |
| 24 | + run_sentry = is_sentry_enabled(); |
| 25 | +#ifndef APPLE |
| 26 | + sentry_options_t *options = sentry_options_new(); |
| 27 | + sentry_options_set_dsn(options, "https://b4723526f0904a27a795406d25f3cc79@o4504135122944000.ingest.sentry.io/4504135125172224"); |
| 28 | + |
| 29 | + // This is also the default-path. For further information and recommendations: |
| 30 | + // https://docs.sentry.io/platforms/native/configuration/options/#database-path |
| 31 | + sentry_options_set_database_path(options, ".sentry-native"); |
| 32 | + sentry_options_set_release(options, "[email protected]"); |
| 33 | + sentry_options_set_debug(options, 1); |
| 34 | + sentry_init(options); |
| 35 | +#endif //APPLE |
| 36 | +} |
| 37 | + |
| 38 | +void fastdup_sentry_close(){ |
| 39 | + if (run_sentry == 0) |
| 40 | + return; |
| 41 | +#ifndef APPLE |
| 42 | + sentry_close(); |
| 43 | +#endif |
| 44 | +} |
| 45 | + |
| 46 | +void fastdup_sentry_report(string logger, string message, sentry_level_t level=SENTRY_LEVEL_ERROR){ |
| 47 | + if (run_sentry == 0) |
| 48 | + return; |
| 49 | + |
| 50 | +#ifndef APPLE |
| 51 | + /* ... */ |
| 52 | + try{ |
| 53 | + sentry_capture_event(sentry_value_new_message_event( |
| 54 | + /* level */ level, |
| 55 | + /* logger */ logger.c_str(), |
| 56 | + /* message */ message.c_str() |
| 57 | + )); |
| 58 | + } |
| 59 | + catch(...){ |
| 60 | + |
| 61 | + }; |
| 62 | +#endif |
| 63 | + |
| 64 | +} |
| 65 | + |
| 66 | +void fastdup_sentry_report_config(){ |
| 67 | + if (run_sentry == 0) |
| 68 | + return; |
| 69 | + |
| 70 | +#ifndef APPLE |
| 71 | + sentry_value_t config = sentry_value_new_object(); |
| 72 | + sentry_value_set_by_key(config, "run_mode", sentry_value_new_int32(run_mode)); |
| 73 | + sentry_value_set_by_key(config, "d", sentry_value_new_int32(d)); |
| 74 | + sentry_value_set_by_key(config, "k", sentry_value_new_int32(nearest_neighbors_k)); |
| 75 | + sentry_value_set_by_key(config, "num_clusters", sentry_value_new_int32(num_clusters)); |
| 76 | + sentry_value_set_by_key(config, "num_em_iter", sentry_value_new_int32(num_em_iter)); |
| 77 | + sentry_value_set_by_key(config, "num_threads", sentry_value_new_int32(num_threads)); |
| 78 | + sentry_value_set_by_key(config, "threshold", sentry_value_new_double(nnthreshold)); |
| 79 | + sentry_value_set_by_key(config, "ccthreshold", sentry_value_new_double(ccthreshold)); |
| 80 | + sentry_value_set_by_key(config, "lower_threshold", sentry_value_new_double(lower_threshold)); |
| 81 | + sentry_value_set_by_key(config, "nn_provider", sentry_value_new_string(nn_provider.c_str())); |
| 82 | + sentry_value_set_by_key(config, "turi_param", sentry_value_new_string(turi_param.c_str())); |
| 83 | + sentry_value_set_by_key(config, "nnf_param", sentry_value_new_string(nnf_params.c_str())); |
| 84 | + sentry_value_set_by_key(config, "verbose", sentry_value_new_bool(verbose)); |
| 85 | + sentry_set_context("config", config); |
| 86 | +#endif |
| 87 | +} |
| 88 | + |
| 89 | +void fastdup_sentry_report_file_size(){ |
| 90 | + if (run_sentry == 0) |
| 91 | + return; |
| 92 | + |
| 93 | +#ifndef APPLE |
| 94 | + sentry_value_t data = sentry_value_new_object(); |
| 95 | + sentry_value_set_by_key(data, "num_images", sentry_value_new_int32((int)num_images)); |
| 96 | + sentry_value_set_by_key(data, "num_images_test", sentry_value_new_int32((int)num_images_test)); |
| 97 | + sentry_value_set_by_key(data, "is_minio", sentry_value_new_bool(global_minio_config.is_minio)); |
| 98 | + sentry_value_set_by_key(data, "is_s3", sentry_value_new_bool(global_minio_config.is_s3)); |
| 99 | + sentry_value_set_by_key(data, "found_video", sentry_value_new_bool(found_video)); |
| 100 | + sentry_value_set_by_key(data, "found_tar", sentry_value_new_bool(found_tar)); |
| 101 | + sentry_value_set_by_key(data, "found_zip", sentry_value_new_bool(found_zip)); |
| 102 | + |
| 103 | + sentry_set_context("data", data); |
| 104 | + |
| 105 | + sentry_value_t performance = sentry_value_new_object(); |
| 106 | + sentry_value_set_by_key(performance, "runtime_sec", sentry_value_new_int32(duration_cast<seconds>(system_clock::now() -start_time).count())); |
| 107 | + sentry_value_set_by_key(performance, "system_mem_mb", sentry_value_new_int32((int)(getTotalSystemMemory()/1000000))); |
| 108 | + sentry_value_set_by_key(performance, "cores", sentry_value_new_int32((int)std::thread::hardware_concurrency())); |
| 109 | + sentry_value_set_by_key(performance, "disk_space", sentry_value_new_string(get_disk_space().c_str())); |
| 110 | + sentry_set_context("performance", performance); |
| 111 | + |
| 112 | + |
| 113 | +#endif //APPLE |
| 114 | +} |
| 115 | + |
| 116 | +#include <stdarg.h> |
| 117 | + |
| 118 | +void fastdup_sentry_report_error_msg(const char * error_type, const char * format, ...){ |
| 119 | + |
| 120 | + int result; |
| 121 | + va_list args; |
| 122 | + |
| 123 | + char msg[2056]; |
| 124 | + va_start(args, format); |
| 125 | + vsprintf(msg, format, args); |
| 126 | + va_end(args); |
| 127 | + |
| 128 | + fprintf(stderr, "%s", msg); |
| 129 | + if (run_sentry == 0) |
| 130 | + return; |
| 131 | + |
| 132 | +#ifndef APPLE |
| 133 | + |
| 134 | + fastdup_sentry_report(error_type, msg); |
| 135 | +#endif //APPLE |
| 136 | +} |
| 137 | +#endif //SENTRY_H__ |
| 138 | + |
0 commit comments