Skip to content

Commit

Permalink
Fix #230: Improve responsiveness on macos: add support for kFSEventSt…
Browse files Browse the repository at this point in the history
…reamCreateFlagNoDefer
  • Loading branch information
emcrisostomo committed Jun 14, 2022
1 parent 36df82b commit 32ecd36
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ NEWS

New in master:

* Issue 230: Improve responsiveness on macos: add support for kFSEventStreamCreateFlagNoDefer.

* Issue 249: Man page still mentions fswatch-run.

* Issue 255: Implement event bubbling.

* Issue 256: -1 flag prints the file changed 3x before exiting.

New in 1.16.0:
Expand Down
8 changes: 8 additions & 0 deletions fswatch/doc/fswatch.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,14 @@ Use the specified @command{@var{monitor}}.
Pass the specified property to the monitor (@pxref{Monitor
Tunables}).

@opsummary{no-defer}
@item --no-defer

Sets the kFSEventStreamCreateFlagNoDefer on the FSEvents monitor, which makes
the monitor more responsive. This flag is more appropriate for interactive
session, while the default behaviour is more appropriate for background,
daemon or batch processing apps.

@opsummary{numeric}
@item --numeric
@itemx -n
Expand Down
19 changes: 19 additions & 0 deletions fswatch/src/fswatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "libfswatch/c/libfswatch.h"
#include "libfswatch/c/libfswatch_log.h"
#include "libfswatch/c++/libfswatch_exception.hpp"
#ifdef HAVE_FSEVENTS_FILE_EVENTS
#include "libfswatch/c++/fsevents_monitor.hpp"
#endif

#ifdef HAVE_GETOPT_LONG
# include <getopt.h>
Expand Down Expand Up @@ -92,6 +95,7 @@ static bool Iflag = false;
static bool Lflag = false;
static bool mflag = false;
static bool nflag = false;
static bool noDeferFlag = false;
static bool oflag = false;
static bool rflag = false;
static bool tflag = false;
Expand Down Expand Up @@ -120,6 +124,7 @@ static const int OPT_ALLOW_OVERFLOW = 132;
static const int OPT_MONITOR_PROPERTY = 133;
static const int OPT_FIRE_IDLE_EVENTS = 134;
static const int OPT_FILTER_FROM = 135;
static const int OPT_NO_DEFER = 136;

static void list_monitor_types(std::ostream& stream)
{
Expand Down Expand Up @@ -167,6 +172,9 @@ static void usage(std::ostream& stream)
stream << " -i, --include=REGEX " << _("Include paths matching REGEX.\n");
stream << " -I, --insensitive " << _("Use case insensitive regular expressions.\n");
stream << " -l, --latency=DOUBLE " << _("Set the latency.\n");
#if defined(HAVE_FSEVENTS_FILE_EVENTS)
stream << " --no-defer " << _("Set the no defer flag in the monitor.\n");
#endif
stream << " -L, --follow-links " << _("Follow symbolic links.\n");
stream << " -M, --list-monitors " << _("List the available monitors.\n");
stream << " -m, --monitor=NAME " << _("Use the specified monitor.\n");
Expand Down Expand Up @@ -486,6 +494,10 @@ static void start_monitor(int argc, char **argv, int optind)
active_monitor->set_properties(monitor_properties);
active_monitor->set_allow_overflow(allow_overflow);
active_monitor->set_latency(lvalue);
#if defined(HAVE_FSEVENTS_FILE_EVENTS)
if (noDeferFlag)
active_monitor->set_property(std::string(fsw::fsevents_monitor::DARWIN_EVENTSTREAM_NO_DEFER), "true");
#endif
active_monitor->set_fire_idle_event(fieFlag);
active_monitor->set_recursive(rflag);
active_monitor->set_directory_only(dflag);
Expand Down Expand Up @@ -525,6 +537,9 @@ static void parse_opts(int argc, char **argv)
{"include", required_argument, nullptr, 'i'},
{"insensitive", no_argument, nullptr, 'I'},
{"latency", required_argument, nullptr, 'l'},
#ifdef HAVE_FSEVENTS_FILE_EVENTS
{"no-defer", no_argument, nullptr, OPT_NO_DEFER},
#endif
{"list-monitors", no_argument, nullptr, 'M'},
{"monitor", required_argument, nullptr, 'm'},
{"monitor-property", required_argument, nullptr, OPT_MONITOR_PROPERTY},
Expand Down Expand Up @@ -686,6 +701,10 @@ static void parse_opts(int argc, char **argv)
filter_files.emplace_back(optarg);
break;

case OPT_NO_DEFER:
noDeferFlag = true;
break;

case '?':
usage(std::cerr);
exit(FSW_EXIT_UNK_OPT);
Expand Down
5 changes: 5 additions & 0 deletions man/fswatch.7.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ Uses the monitor specified by
The list of currently available monitors can be obtained using the
.Fl h
option.
.It Fl -no-defer
Sets the kFSEventStreamCreateFlagNoDefer flag on macOS FSEvents monitor, which
makes the monitor more responsive. This flag is more appropriate for
sessions, while the default behaviour is more appropriate for background,
daemon or batch processing apps.
.It Fl n, -numeric
Print the numeric value of the event flag, instead of the array of symbolic
names. The numeric value of the event flags are system-specific and may vary
Expand Down

0 comments on commit 32ecd36

Please sign in to comment.