From 37415a15e43d9b087e860f8223188ac4c2070c73 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 6 Jul 2023 11:33:42 +0200 Subject: [PATCH] [Debugger] Enable file watchers on demand due to inotify limit on Linux --- src/Libs/FShade.Debug/Debugger.fs | 4 +++- src/Libs/FShade.Debug/FileWatchers.fs | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Libs/FShade.Debug/Debugger.fs b/src/Libs/FShade.Debug/Debugger.fs index b974c13..4f22e97 100644 --- a/src/Libs/FShade.Debug/Debugger.fs +++ b/src/Libs/FShade.Debug/Debugger.fs @@ -235,7 +235,9 @@ module ShaderDebugger = Report.Line(2, $"{definition} - {definition.Location}") success <- true - projects.[definition.Project].Callbacks.Add update + let project = projects.[definition.Project] + project.Callbacks.Add update + FileWatchers.activate project.Data shaderCache.[id] <- (definition, cval) string definition, cval diff --git a/src/Libs/FShade.Debug/FileWatchers.fs b/src/Libs/FShade.Debug/FileWatchers.fs index 4312929..cda96b4 100644 --- a/src/Libs/FShade.Debug/FileWatchers.fs +++ b/src/Libs/FShade.Debug/FileWatchers.fs @@ -2,6 +2,7 @@ open System.IO open System.Collections.Generic +open Aardvark.Base module internal FileWatchers = @@ -19,7 +20,6 @@ module internal FileWatchers = | (true, w) -> w | _ -> let w = new FileSystemWatcher(dir) - w.EnableRaisingEvents <- true watchers.[dir] <- w w @@ -27,6 +27,25 @@ module internal FileWatchers = watcher.Renamed.Add (fun e -> if Set.contains e.FullPath files then callback e.FullPath) watcher.Created.Add (fun e -> if Set.contains e.FullPath files then callback e.FullPath) + // Enables the file watchers for the given project. + // On Linux there is a limit on how many file watcher can be active so we only activate them on demand. + // See: https://travisgosselin.com/configured-user-limit-inotify-instances/ + let activate (project : ProjectData) = + let directories = + project.Files + |> List.map Path.GetDirectoryName + |> List.distinct + + for dir in directories do + match watchers.TryGetValue dir with + | (true, w) -> + try + w.EnableRaisingEvents <- true + with exn -> + Log.warn "[FShade] Could not enable file watcher for directory '%s': %s" dir exn.Message + | _ -> + Log.warn "[FShade] File watcher for directory '%s' not found" dir + let dispose() = for w in watchers.Values do w.Dispose() watchers.Clear() \ No newline at end of file