generated from yandex-praktikum/go-musthave-shortener-tpl
/
main.go
56 lines (48 loc) · 1.71 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
// Сервис сокращения URL
//
// Приложение чистой архитектуры.
// Сервис сохраняет URL переданный на его API и возвращает укороченный URL,
// перейдя по которому получите тот же результат, что и при переходе по-длинному URL.
//
// Copyright 2023 Developer Team. All rights reserved
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file
package main
import (
"flag"
"log"
_ "net/http/pprof" // подключаем пакет pprof
"os"
"runtime"
"runtime/pprof"
"github.com/SETTER2000/shorturl/internal/app"
)
var cpuprofile = flag.String("cpuprofile", "", "записать профиль процессора в `file`")
var memprofile = flag.String("memprofile", "", "записать профиль памяти в `file`")
func main() {
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close() // error handling omitted for example
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
// ... rest of the program ...
// Run
app.Run()
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal("не удалось создать профиль памяти: ", err)
}
defer f.Close()
runtime.GC() // получать актуальную статистику
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("не удалось записать профиль памяти: ", err)
}
}
}