-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
66 lines (54 loc) · 1.86 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"runtime"
"time"
"github.com/gosuri/uilive"
"github.com/gosuri/uitable"
"github.com/paulbellamy/ratecounter"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
type Stats struct {
URIsPerSecond *ratecounter.RateCounter
ParsedCounter *ratecounter.Counter
DuplicateCounter *ratecounter.Counter
UniqueCounter *ratecounter.Counter
HostsCount *ratecounter.Counter
ExcludedCounter *ratecounter.Counter
SeedsListSize *ratecounter.Counter
ParsingFailures *ratecounter.Counter
StartTime time.Time
FilePath string
FileProcessingCount int
FilesCount int
}
func (s *Stats) printLiveStats() {
var stats *uitable.Table
var m runtime.MemStats
p := message.NewPrinter(language.English)
writer := uilive.New()
writer.Start()
for {
runtime.ReadMemStats(&m)
stats = uitable.New()
stats.MaxColWidth = 80
stats.Wrap = true
stats.AddRow("", "")
stats.AddRow(" - File:", fmt.Sprintf("%s [%d/%d]", s.FilePath, s.FileProcessingCount, s.FilesCount))
stats.AddRow(" - Speed:", p.Sprintf("%d URI/s", s.URIsPerSecond.Rate()))
stats.AddRow(" - Parsed:", p.Sprintf("%d URIs", s.ParsedCounter.Value()))
stats.AddRow(" - Unique:", p.Sprintf("%d URIs", s.UniqueCounter.Value()))
stats.AddRow(" - Duplicate:", p.Sprintf("%d URIs", s.DuplicateCounter.Value()))
if arguments.MaxHostOccurrence != -1 || len(arguments.ExcludedHosts) > 0 {
stats.AddRow(" - Excluded:", p.Sprintf("%d URIs", s.ExcludedCounter.Value()))
stats.AddRow(" - Unique hosts:", p.Sprintf("%d", s.HostsCount.Value()))
}
stats.AddRow("", "")
stats.AddRow(" - Final seeds list size:", p.Sprintf("%d URIs", s.SeedsListSize.Value()))
stats.AddRow(" - Elapsed time:", time.Since(s.StartTime))
fmt.Fprintln(writer, stats.String())
writer.Flush()
time.Sleep(time.Second / 4)
}
}