Skip to content

Commit

Permalink
[Debugger] Enable file watchers on demand due to inotify limit on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jul 6, 2023
1 parent 379e3ab commit 37415a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Libs/FShade.Debug/Debugger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion src/Libs/FShade.Debug/FileWatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System.IO
open System.Collections.Generic
open Aardvark.Base

module internal FileWatchers =

Expand All @@ -19,14 +20,32 @@ module internal FileWatchers =
| (true, w) -> w
| _ ->
let w = new FileSystemWatcher(dir)
w.EnableRaisingEvents <- true
watchers.[dir] <- w
w

watcher.Changed.Add (fun e -> if Set.contains e.FullPath files then callback e.FullPath)
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()

0 comments on commit 37415a1

Please sign in to comment.