2015-02-05 19:29:27 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-02-05 19:29:27 +00:00
|
|
|
|
2019-03-26 19:53:58 +00:00
|
|
|
package ur
|
2015-02-05 19:29:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-06-23 08:47:15 +00:00
|
|
|
func memorySize() int64 {
|
2015-02-05 19:29:27 +00:00
|
|
|
cmd := exec.Command("/sbin/sysctl", "hw.physmem64")
|
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
2020-06-23 08:47:15 +00:00
|
|
|
return 0
|
2015-02-05 19:29:27 +00:00
|
|
|
}
|
|
|
|
fs := strings.Fields(string(out))
|
|
|
|
if len(fs) != 3 {
|
2020-06-23 08:47:15 +00:00
|
|
|
return 0
|
2015-02-05 19:29:27 +00:00
|
|
|
}
|
|
|
|
bytes, err := strconv.ParseInt(fs[2], 10, 64)
|
|
|
|
if err != nil {
|
2020-06-23 08:47:15 +00:00
|
|
|
return 0
|
2015-02-05 19:29:27 +00:00
|
|
|
}
|
2020-06-23 08:47:15 +00:00
|
|
|
return bytes
|
2015-02-05 19:29:27 +00:00
|
|
|
}
|