Skip to content

Commit

Permalink
chg: wrapped stats with #if DETAILED_STATS
Browse files Browse the repository at this point in the history
  • Loading branch information
elsamuko committed Dec 8, 2020
1 parent bcd1c8c commit c7750aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/fsrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

int main( int argc, char* argv[] ) {

#if DETAILED_STATS
StopWatch total;
total.start();
#endif

SearchOptions opts = SearchOptions::parseArgs( argc, argv );

Expand All @@ -32,12 +34,11 @@ int main( int argc, char* argv[] ) {
searcher.onAllFiles();
}

auto ms = total.stop() / 1000000;

#if DETAILED_STATS
auto ms = total.stop() / 1000000;
searcher.printStats();
#endif
searcher.printFooter( ms );
#endif

ExitQueue::call();
return 0;
Expand Down
10 changes: 10 additions & 0 deletions src/searchcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ void SearchController::onAllFiles() {

utils::recurseDir( opts.path.native(), [&pool, this]( const sys_string & filename ) {
pool.add( [filename, this] {
#if DETAILED_STATS
stats.filesSearched++;
#endif
search( filename );
} );
} );
Expand All @@ -30,7 +32,9 @@ void SearchController::onGitFiles() {

utils::gitLsFiles( opts.path, [&pool, this]( const sys_string & filename ) {
pool.add( [filename, this] {
#if DETAILED_STATS
stats.filesSearched++;
#endif
search( filename );
} );
} );
Expand All @@ -50,6 +54,7 @@ void SearchController::printGitHeader() {
}
}

#if DETAILED_STATS
void SearchController::printStats() {
if( !opts.piped ) {
utils::printColor( gray, utils::format(
Expand All @@ -74,6 +79,7 @@ void SearchController::printFooter( const StopWatch::ns_type& ms ) {
ms ) );
}
}
#endif

void SearchController::search( const sys_string& path ) {

Expand All @@ -87,7 +93,9 @@ void SearchController::search( const sys_string& path ) {
utils::FileView view = utils::fromWinAPI( path );
#endif

#if DETAILED_STATS
stats.bytesRead += view.size;
#endif
STOP( stats.t_read )

if( !view.size ) { return; }
Expand All @@ -103,8 +111,10 @@ void SearchController::search( const sys_string& path ) {

// handle matches
if( !matches.empty() ) {
#if DETAILED_STATS
stats.filesMatched++;
stats.matches += matches.size();
#endif

START
static thread_local std::unique_ptr<Printer> printer( makePrinter() );
Expand Down
2 changes: 2 additions & 0 deletions src/searchcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct SearchController {
SearchOptions opts;
std::function<Searcher*()> makeSearcher;
std::function<Printer*()> makePrinter;
#if DETAILED_STATS
Stats stats;
#endif
Color gray = Color::Gray;

SearchController( const SearchOptions& opts, std::function<Searcher*()> searcher, std::function<Printer*()> printer ):
Expand Down

0 comments on commit c7750aa

Please sign in to comment.