forked from hyperjiang/php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.go
38 lines (34 loc) · 858 Bytes
/
misc.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
package php
import (
"errors"
"os"
"runtime"
"strings"
)
// Getenv gets the value of an environment variable
func Getenv(varname string) string {
return os.Getenv(varname)
}
// Putenv sets the value of an environment variable
//
// The setting should be a key-value pair, like "FOO=BAR"
func Putenv(setting string) error {
s := strings.Split(setting, "=")
if len(s) != 2 {
return errors.New("Invalid setting: " + setting)
}
return os.Setenv(s[0], s[1])
}
// MemoryGetUsage returns the amount of allocated memory in bytes
//
// Set realUsage to TRUE to get total memory allocated from system, including unused pages
//
// If realUsage is FALSE then only the used memory is reported
func MemoryGetUsage(realUsage bool) uint64 {
stat := new(runtime.MemStats)
runtime.ReadMemStats(stat)
if realUsage {
return stat.Sys
}
return stat.Alloc
}