/
main.go
97 lines (81 loc) · 2.41 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2019 Alberto Bregliano. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"time"
"context"
"flag"
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"github.com/axamon/hermes/parsers"
)
// Version è la versione attuale di Hermes.
const Version = "4.3.3_beta"
var stat = flag.Bool("stat", false, "riporta a video delle statistiche")
var version = flag.Bool("version", false, "mostra la versione software")
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
var goroutines = flag.Int("g", 1000, "Numero di processi paralleli da usare")
var logfile = flag.String("f", "", "Logfile da parsare")
var tipo = flag.String("t", "", "tipo Logfile da parsare")
func main() {
flag.Parse()
var start = time.Now()
if *version {
fmt.Printf("Hermes Versione: %s\n", Version)
os.Exit(0)
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Così evitiamo problemi con l'istanzioamento degli errori :)
var err error
switch *tipo {
case "CDN":
err = parsers.CDN(ctx, *logfile, *goroutines)
if err != nil {
log.Printf("Error Impossibile parsare file CDN %s: %s\n", *logfile, err.Error())
}
case "REGMAN":
err = parsers.REGMAN(ctx, *logfile, *goroutines)
if err != nil {
log.Printf("Error Impossibile parsare file REGMAN %s: %s\n", *logfile, err.Error())
}
case "AVS":
err = parsers.AVS(ctx, *logfile)
if err != nil {
log.Printf("Error Impossibile parsare file AVS %s: %s\n", *logfile, err.Error())
}
default:
fmt.Println("Specifica tipo di file: [CDN AVS REGMAN]")
}
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer f.Close()
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
}
if *stat {
// start := time.Now()
log.Printf("Elaborazione %s: %v\n", *logfile, time.Since(start))
}
}