| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #pragma once | 18 #pragma once |
| 19 | 19 |
| 20 #include <emscripten.h> | 20 #include "library.h" |
| 21 #include <emscripten/trace.h> | |
| 22 | 21 |
| 23 #if defined(assert) | 22 #if defined(assert) |
| 24 #undef assert | 23 #undef assert |
| 25 #endif | 24 #endif |
| 26 | 25 |
| 27 class String; | 26 class String; |
| 28 | 27 |
| 29 struct console_type | 28 struct console_type |
| 30 { | 29 { |
| 31 static void log(const String& str) | 30 static void log(const String& str) |
| 32 { | 31 { |
| 33 EM_ASM_ARGS(console.log(readString($0)), &str); | 32 LogString(str); |
| 34 } | 33 } |
| 35 | 34 |
| 36 static void log(int i) | 35 static void log(int i) |
| 37 { | 36 { |
| 38 EM_ASM_ARGS(console.log($0), i); | 37 LogInteger(i); |
| 39 } | 38 } |
| 40 | 39 |
| 41 static void log(void* ptr) | 40 static void log(const void* ptr) |
| 42 { | 41 { |
| 43 EM_ASM_ARGS(console.log($0), ptr); | 42 LogPointer(ptr); |
| 44 } | 43 } |
| 45 | 44 |
| 46 static void error(const String& str) | 45 static void error(const String& str) |
| 47 { | 46 { |
| 48 EM_ASM_ARGS(console.error(new Error(readString($0)).stack), &str); | 47 LogError(str); |
| 49 } | 48 } |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 static console_type console; | 51 static console_type console; |
| 53 | 52 |
| 54 #if defined(DEBUG) | 53 #if defined(DEBUG) |
| 55 inline void assert(bool condition, const String& str) | 54 inline void assert(bool condition, const String& str) |
| 56 { | 55 { |
| 57 if (!condition) | 56 if (!condition) |
| 58 console.error(str); | 57 console.error(str); |
| 59 } | 58 } |
| 60 #else | 59 #else |
| 61 #define assert(condition, str) | 60 #define assert(condition, str) |
| 62 #endif | 61 #endif |
| 63 | 62 |
| 63 #if defined(__EMSCRIPTEN_TRACING__) |
| 64 #include <emscripten/trace.h> |
| 65 |
| 66 inline void init_tracing() |
| 67 { |
| 68 emscripten_trace_configure("http://127.0.0.1:5000/", "MyApplication"); |
| 69 } |
| 70 |
| 71 inline void shutdown_tracing() |
| 72 { |
| 73 emscripten_trace_close(); |
| 74 } |
| 75 |
| 64 inline void annotate_address(void* address, const char* name) | 76 inline void annotate_address(void* address, const char* name) |
| 65 { | 77 { |
| 66 #if defined(__EMSCRIPTEN_TRACING__) | |
| 67 emscripten_trace_annotate_address_type(address, name); | 78 emscripten_trace_annotate_address_type(address, name); |
| 68 #endif | |
| 69 } | 79 } |
| 70 | 80 |
| 71 inline void enter_context(const char* context) | 81 inline void enter_context(const char* context) |
| 72 { | 82 { |
| 73 #if defined(__EMSCRIPTEN_TRACING__) | |
| 74 emscripten_trace_enter_context(context); | 83 emscripten_trace_enter_context(context); |
| 75 #endif | |
| 76 } | 84 } |
| 77 | 85 |
| 78 inline void exit_context() | 86 inline void exit_context() |
| 79 { | 87 { |
| 80 #if defined(__EMSCRIPTEN_TRACING__) | |
| 81 emscripten_trace_exit_context(); | 88 emscripten_trace_exit_context(); |
| 82 #endif | |
| 83 } | 89 } |
| 90 |
| 91 #else // defined(__EMSCRIPTEN_TRACING__) |
| 92 |
| 93 inline void init_tracing() |
| 94 { |
| 95 } |
| 96 |
| 97 inline void shutdown_tracing() |
| 98 { |
| 99 } |
| 100 |
| 101 inline void annotate_address(void* address, const char* name) |
| 102 { |
| 103 } |
| 104 |
| 105 inline void enter_context(const char* context) |
| 106 { |
| 107 } |
| 108 |
| 109 inline void exit_context() |
| 110 { |
| 111 } |
| 112 |
| 113 #endif // defined(__EMSCRIPTEN_TRACING__) |
| OLD | NEW |