Merge pull request #223 from projectdiscovery/add-time-taken
Add feature to show time taken by each sourcemaster
commit
771164af63
|
@ -40,6 +40,9 @@ var (
|
|||
Fatal: "FTL",
|
||||
Info: "INF",
|
||||
}
|
||||
|
||||
// mutex protects the current logger
|
||||
mutex = &sync.Mutex{}
|
||||
)
|
||||
|
||||
var stringBuilderPool = &sync.Pool{New: func() interface{} {
|
||||
|
@ -114,12 +117,14 @@ func log(level Level, label string, format string, args ...interface{}) {
|
|||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
switch level {
|
||||
case Silent:
|
||||
fmt.Fprintf(os.Stdout, sb.String())
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, sb.String())
|
||||
}
|
||||
mutex.Unlock()
|
||||
|
||||
sb.Reset()
|
||||
stringBuilderPool.Put(sb)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/projectdiscovery/subfinder/pkg/log"
|
||||
"github.com/projectdiscovery/subfinder/pkg/subscraping"
|
||||
)
|
||||
|
||||
|
@ -21,20 +22,34 @@ func (a *Agent) EnumerateSubdomains(domain string, keys subscraping.Keys, timeou
|
|||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), maxEnumTime)
|
||||
|
||||
timeTaken := make(map[string]string)
|
||||
timeTakenMutex := &sync.Mutex{}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
// Run each source in parallel on the target domain
|
||||
for source, runner := range a.sources {
|
||||
wg.Add(1)
|
||||
|
||||
now := time.Now()
|
||||
go func(source string, runner subscraping.Source) {
|
||||
for resp := range runner.Run(ctx, domain, session) {
|
||||
results <- resp
|
||||
}
|
||||
|
||||
duration := time.Now().Sub(now)
|
||||
timeTakenMutex.Lock()
|
||||
timeTaken[source] = fmt.Sprintf("Source took %s for enumeration\n", duration)
|
||||
timeTakenMutex.Unlock()
|
||||
|
||||
wg.Done()
|
||||
}(source, runner)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
for source, data := range timeTaken {
|
||||
log.Verbosef(data, source)
|
||||
}
|
||||
|
||||
close(results)
|
||||
cancel()
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue