-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.go
82 lines (71 loc) · 1.8 KB
/
processor.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
/*
* Copyright 2014–2018 Kullo GmbH
*
* This source code is licensed under the 3-clause BSD license. See LICENSE.txt
* in the root directory of this source tree for details.
*/
package main
import (
"fmt"
"io/ioutil"
"log"
"os/exec"
)
var crashIds = make(chan string, 100)
func readAllFromCommand(cmd *exec.Cmd) ([]byte, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
err = cmd.Start()
if err != nil {
return nil, err
}
stdoutBytes, err := ioutil.ReadAll(stdout)
if err != nil {
return nil, err
}
err = cmd.Wait()
if err != nil {
return nil, err
}
return stdoutBytes, nil
}
func pullGit(repository string) error {
cmd := exec.Command("git", "-C", repository, "pull")
return cmd.Run()
}
func StartCrashreportProcessorWorker() {
go func() {
linux32Symbols := *symbolsDirectory + "/linux32"
linux64Symbols := *symbolsDirectory + "/linux64"
osxSymbols := *symbolsDirectory + "/osx"
windowsSymbols := *symbolsDirectory + "/windows"
for {
id := <-crashIds
baseFilename := *dumpDirectory + "/" + id
//metadataFilename := baseFilename + ".json"
minidumpFilename := baseFilename + ".dmp"
stacktraceFilename := baseFilename + ".trace"
err := pullGit(*symbolsDirectory)
if err != nil {
log.Print("Failed to pull git")
}
cmd := exec.Command("minidump_stackwalk", minidumpFilename,
linux32Symbols, linux64Symbols, osxSymbols, windowsSymbols)
stdout, err := readAllFromCommand(cmd)
if err != nil {
log.Print(fmt.Sprintf("Failed to process minidump %s", minidumpFilename))
continue
}
err = ioutil.WriteFile(stacktraceFilename, stdout, 0600)
if err != nil {
log.Print(fmt.Sprintf("Failed to write stacktrace %s", stacktraceFilename))
continue
}
}
}()
}
func ProcessCrashreport(id string) {
crashIds <- id
}