Browse Source

Remove ENABLE_PROFILER (is configured via cargo.toml)

Fabian 3 years ago
parent
commit
693b905013
4 changed files with 20 additions and 22 deletions
  1. 15 15
      src/browser/main.js
  2. 0 5
      src/config.js
  3. 2 2
      src/cpu.js
  4. 3 0
      src/rust/profiler.rs

+ 15 - 15
src/browser/main.js

@@ -1294,27 +1294,27 @@
             if(DEBUG)
             {
                 debug_start(emulator);
-            }
 
-            const CLEAR_STATS = false;
+                if(emulator.v86.cpu.wm.exports["profiler_is_enabled"]())
+                {
+                    const CLEAR_STATS = false;
 
-            var panel = document.createElement("pre");
-            document.body.appendChild(panel);
+                    var panel = document.createElement("pre");
+                    document.body.appendChild(panel);
 
-            if(ENABLE_PROFILER)
-            {
-                setInterval(function()
-                    {
-                        if(!emulator.is_running())
+                    setInterval(function()
                         {
-                            return;
-                        }
+                            if(!emulator.is_running())
+                            {
+                                return;
+                            }
 
-                        const text = print_stats.stats_to_string(emulator.v86.cpu);
-                        panel.textContent = text;
+                            const text = print_stats.stats_to_string(emulator.v86.cpu);
+                            panel.textContent = text;
 
-                        CLEAR_STATS && emulator.v86.cpu.wm.exports["_profiler_init"]();
-                    }, CLEAR_STATS ? 5000 : 1000);
+                            CLEAR_STATS && emulator.v86.cpu.wm.exports["_profiler_init"]();
+                        }, CLEAR_STATS ? 5000 : 1000);
+                }
             }
 
             init_ui(settings, emulator);

+ 0 - 5
src/config.js

@@ -9,11 +9,6 @@
  */
 var DEBUG = true;
 
-/** @const
- * Also needs to be set in cargo.toml
- */
-var ENABLE_PROFILER = false;
-
 /** @const */
 var LOG_TO_FILE = false;
 

+ 2 - 2
src/cpu.js

@@ -1352,14 +1352,14 @@ let do_many_cycles_total = 0;
 
 CPU.prototype.do_many_cycles = function()
 {
-    if(ENABLE_PROFILER)
+    if(DEBUG)
     {
         var start_time = v86.microtick();
     }
 
     this.do_many_cycles_native();
 
-    if(ENABLE_PROFILER)
+    if(DEBUG)
     {
         do_many_cycles_total += v86.microtick() - start_time;
         do_many_cycles_count++;

+ 3 - 0
src/rust/profiler.rs

@@ -101,5 +101,8 @@ pub fn profiler_stat_get(stat: stat) -> f64 {
     }
 }
 
+#[no_mangle]
+pub fn profiler_is_enabled() -> bool { cfg!(feature = "profiler") }
+
 #[no_mangle]
 pub fn profiler_stat_increment_do_run() { stat_increment(stat::DO_RUN); }