if use go1.7
in runtime/malloc.go file add mallocgc debug info and go install and go run
x.go I will get a error "signal: segmentation fault"
in go1.4.2 will not
func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
println("mallocgc:size=", size, "kind=", typ.kind, "needzero=",
needzero)
在 2016年9月29日星期四 UTC+8下午9:04:58,Dave Cheney写道:
>
> You should use Go 1.7.1 or later.
>
> On Thursday, 29 September 2016 23:00:25 UTC+10, 刘桂祥 wrote:
>>
>> package main
>>
>> import "runtime"
>>
>> func main() {
>> m := new(runtime.MemStats)
>> runtime.ReadMemStats(m)
>> cap := 1024
>> println("debug0")
>> s := make([]byte, cap)
>> println("debug1")
>> _ = s
>> runtime.ReadMemStats(m)
>> println("memstats:", m.Alloc, m.Mallocs)
>> }
>>
>> I use go1.4.2 and In go source code add mallocgc debug info
>> here is the result:
>> debug0
>> mallocgc: 1024
>> mallocgc: 272
>> mallocgc: 32
>> debug1
>>
>> I doubt there is other goroutine call the mallocgc
>>
>> but if I use go test -bench="." makeslice_test.go
>> func BenchmarkMakeSlice2(b *testing.B) {
>> b.ReportAllocs()
>> cap := 1024
>> for i := 0; i < b.N; i++ {
>> s := make([]byte, cap, cap)
>> _ = s
>> }
>> }
>> the output is:
>> 14120 ns/op 1024 B/op 1 allocs/op
>> I infer the go test know all the mallocgc and also know which is user's
>> source code to call it
>>
>> my guess
>>
>> 在 2016年9月29日星期四 UTC+8下午5:30:54,Dave Cheney写道:
>>
>>> Sorry, you'll have to work harder to generate a memory profile. My
>>> github.com/pkg/profile package may help automate some of the work, but
>>> may introduce a few allocations of its own which you will have to filter
>>> out.
>>
>>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.