mprof.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Malloc profiling.
  5. // Patterned after tcmalloc's algorithms; shorter code.
  6. package runtime
  7. import (
  8. "unsafe"
  9. )
  10. // NOTE(rsc): Everything here could use cas if contention became an issue.
  11. var proflock mutex
  12. // All memory allocations are local and do not escape outside of the profiler.
  13. // The profiler is forbidden from referring to garbage-collected memory.
  14. const (
  15. // profile types
  16. memProfile bucketType = 1 + iota
  17. blockProfile
  18. // size of bucket hash table
  19. buckHashSize = 179999
  20. // max depth of stack to record in bucket
  21. maxStack = 32
  22. )
  23. type bucketType int
  24. // A bucket holds per-call-stack profiling information.
  25. // The representation is a bit sleazy, inherited from C.
  26. // This struct defines the bucket header. It is followed in
  27. // memory by the stack words and then the actual record
  28. // data, either a memRecord or a blockRecord.
  29. //
  30. // Per-call-stack profiling information.
  31. // Lookup by hashing call stack into a linked-list hash table.
  32. type bucket struct {
  33. next *bucket
  34. allnext *bucket
  35. typ bucketType // memBucket or blockBucket
  36. hash uintptr
  37. size uintptr
  38. nstk uintptr
  39. }
  40. // A memRecord is the bucket data for a bucket of type memProfile,
  41. // part of the memory profile.
  42. type memRecord struct {
  43. // The following complex 3-stage scheme of stats accumulation
  44. // is required to obtain a consistent picture of mallocs and frees
  45. // for some point in time.
  46. // The problem is that mallocs come in real time, while frees
  47. // come only after a GC during concurrent sweeping. So if we would
  48. // naively count them, we would get a skew toward mallocs.
  49. //
  50. // Mallocs are accounted in recent stats.
  51. // Explicit frees are accounted in recent stats.
  52. // GC frees are accounted in prev stats.
  53. // After GC prev stats are added to final stats and
  54. // recent stats are moved into prev stats.
  55. allocs uintptr
  56. frees uintptr
  57. alloc_bytes uintptr
  58. free_bytes uintptr
  59. // changes between next-to-last GC and last GC
  60. prev_allocs uintptr
  61. prev_frees uintptr
  62. prev_alloc_bytes uintptr
  63. prev_free_bytes uintptr
  64. // changes since last GC
  65. recent_allocs uintptr
  66. recent_frees uintptr
  67. recent_alloc_bytes uintptr
  68. recent_free_bytes uintptr
  69. }
  70. // A blockRecord is the bucket data for a bucket of type blockProfile,
  71. // part of the blocking profile.
  72. type blockRecord struct {
  73. count int64
  74. cycles int64
  75. }
  76. var (
  77. mbuckets *bucket // memory profile buckets
  78. bbuckets *bucket // blocking profile buckets
  79. buckhash *[179999]*bucket
  80. bucketmem uintptr
  81. )
  82. // newBucket allocates a bucket with the given type and number of stack entries.
  83. func newBucket(typ bucketType, nstk int) *bucket {
  84. size := unsafe.Sizeof(bucket{}) + uintptr(nstk)*unsafe.Sizeof(uintptr(0))
  85. switch typ {
  86. default:
  87. gothrow("invalid profile bucket type")
  88. case memProfile:
  89. size += unsafe.Sizeof(memRecord{})
  90. case blockProfile:
  91. size += unsafe.Sizeof(blockRecord{})
  92. }
  93. b := (*bucket)(persistentalloc(size, 0, &memstats.buckhash_sys))
  94. bucketmem += size
  95. b.typ = typ
  96. b.nstk = uintptr(nstk)
  97. return b
  98. }
  99. // stk returns the slice in b holding the stack.
  100. func (b *bucket) stk() []uintptr {
  101. stk := (*[maxStack]uintptr)(add(unsafe.Pointer(b), unsafe.Sizeof(*b)))
  102. return stk[:b.nstk:b.nstk]
  103. }
  104. // mp returns the memRecord associated with the memProfile bucket b.
  105. func (b *bucket) mp() *memRecord {
  106. if b.typ != memProfile {
  107. gothrow("bad use of bucket.mp")
  108. }
  109. data := add(unsafe.Pointer(b), unsafe.Sizeof(*b)+b.nstk*unsafe.Sizeof(uintptr(0)))
  110. return (*memRecord)(data)
  111. }
  112. // bp returns the blockRecord associated with the blockProfile bucket b.
  113. func (b *bucket) bp() *blockRecord {
  114. if b.typ != blockProfile {
  115. gothrow("bad use of bucket.bp")
  116. }
  117. data := add(unsafe.Pointer(b), unsafe.Sizeof(*b)+b.nstk*unsafe.Sizeof(uintptr(0)))
  118. return (*blockRecord)(data)
  119. }
  120. // Return the bucket for stk[0:nstk], allocating new bucket if needed.
  121. func stkbucket(typ bucketType, size uintptr, stk []uintptr, alloc bool) *bucket {
  122. if buckhash == nil {
  123. buckhash = (*[buckHashSize]*bucket)(sysAlloc(unsafe.Sizeof(*buckhash), &memstats.buckhash_sys))
  124. if buckhash == nil {
  125. gothrow("runtime: cannot allocate memory")
  126. }
  127. }
  128. // Hash stack.
  129. var h uintptr
  130. for _, pc := range stk {
  131. h += pc
  132. h += h << 10
  133. h ^= h >> 6
  134. }
  135. // hash in size
  136. h += size
  137. h += h << 10
  138. h ^= h >> 6
  139. // finalize
  140. h += h << 3
  141. h ^= h >> 11
  142. i := int(h % buckHashSize)
  143. for b := buckhash[i]; b != nil; b = b.next {
  144. if b.typ == typ && b.hash == h && b.size == size && eqslice(b.stk(), stk) {
  145. return b
  146. }
  147. }
  148. if !alloc {
  149. return nil
  150. }
  151. // Create new bucket.
  152. b := newBucket(typ, len(stk))
  153. copy(b.stk(), stk)
  154. b.hash = h
  155. b.size = size
  156. b.next = buckhash[i]
  157. buckhash[i] = b
  158. if typ == memProfile {
  159. b.allnext = mbuckets
  160. mbuckets = b
  161. } else {
  162. b.allnext = bbuckets
  163. bbuckets = b
  164. }
  165. return b
  166. }
  167. func sysAlloc(n uintptr, stat *uint64) unsafe.Pointer
  168. func eqslice(x, y []uintptr) bool {
  169. if len(x) != len(y) {
  170. return false
  171. }
  172. for i, xi := range x {
  173. if xi != y[i] {
  174. return false
  175. }
  176. }
  177. return true
  178. }
  179. func mprof_GC() {
  180. for b := mbuckets; b != nil; b = b.allnext {
  181. mp := b.mp()
  182. mp.allocs += mp.prev_allocs
  183. mp.frees += mp.prev_frees
  184. mp.alloc_bytes += mp.prev_alloc_bytes
  185. mp.free_bytes += mp.prev_free_bytes
  186. mp.prev_allocs = mp.recent_allocs
  187. mp.prev_frees = mp.recent_frees
  188. mp.prev_alloc_bytes = mp.recent_alloc_bytes
  189. mp.prev_free_bytes = mp.recent_free_bytes
  190. mp.recent_allocs = 0
  191. mp.recent_frees = 0
  192. mp.recent_alloc_bytes = 0
  193. mp.recent_free_bytes = 0
  194. }
  195. }
  196. // Record that a gc just happened: all the 'recent' statistics are now real.
  197. func mProf_GC() {
  198. lock(&proflock)
  199. mprof_GC()
  200. unlock(&proflock)
  201. }
  202. // Called by malloc to record a profiled block.
  203. func mProf_Malloc(p unsafe.Pointer, size uintptr) {
  204. var stk [maxStack]uintptr
  205. nstk := callers(4, &stk[0], len(stk))
  206. lock(&proflock)
  207. b := stkbucket(memProfile, size, stk[:nstk], true)
  208. mp := b.mp()
  209. mp.recent_allocs++
  210. mp.recent_alloc_bytes += size
  211. unlock(&proflock)
  212. // Setprofilebucket locks a bunch of other mutexes, so we call it outside of proflock.
  213. // This reduces potential contention and chances of deadlocks.
  214. // Since the object must be alive during call to mProf_Malloc,
  215. // it's fine to do this non-atomically.
  216. setprofilebucket(p, b)
  217. }
  218. func setprofilebucket_m() // mheap.c
  219. func setprofilebucket(p unsafe.Pointer, b *bucket) {
  220. g := getg()
  221. g.m.ptrarg[0] = p
  222. g.m.ptrarg[1] = unsafe.Pointer(b)
  223. onM(setprofilebucket_m)
  224. }
  225. // Called when freeing a profiled block.
  226. func mProf_Free(b *bucket, size uintptr, freed bool) {
  227. lock(&proflock)
  228. mp := b.mp()
  229. if freed {
  230. mp.recent_frees++
  231. mp.recent_free_bytes += size
  232. } else {
  233. mp.prev_frees++
  234. mp.prev_free_bytes += size
  235. }
  236. unlock(&proflock)
  237. }
  238. var blockprofilerate uint64 // in CPU ticks
  239. // SetBlockProfileRate controls the fraction of goroutine blocking events
  240. // that are reported in the blocking profile. The profiler aims to sample
  241. // an average of one blocking event per rate nanoseconds spent blocked.
  242. //
  243. // To include every blocking event in the profile, pass rate = 1.
  244. // To turn off profiling entirely, pass rate <= 0.
  245. func SetBlockProfileRate(rate int) {
  246. var r int64
  247. if rate <= 0 {
  248. r = 0 // disable profiling
  249. } else if rate == 1 {
  250. r = 1 // profile everything
  251. } else {
  252. // convert ns to cycles, use float64 to prevent overflow during multiplication
  253. r = int64(float64(rate) * float64(tickspersecond()) / (1000 * 1000 * 1000))
  254. if r == 0 {
  255. r = 1
  256. }
  257. }
  258. atomicstore64(&blockprofilerate, uint64(r))
  259. }
  260. func blockevent(cycles int64, skip int) {
  261. if cycles <= 0 {
  262. cycles = 1
  263. }
  264. rate := int64(atomicload64(&blockprofilerate))
  265. if rate <= 0 || (rate > cycles && int64(fastrand1())%rate > cycles) {
  266. return
  267. }
  268. gp := getg()
  269. var nstk int
  270. var stk [maxStack]uintptr
  271. if gp.m.curg == nil || gp.m.curg == gp {
  272. nstk = callers(skip, &stk[0], len(stk))
  273. } else {
  274. nstk = gcallers(gp.m.curg, skip, &stk[0], len(stk))
  275. }
  276. lock(&proflock)
  277. b := stkbucket(blockProfile, 0, stk[:nstk], true)
  278. b.bp().count++
  279. b.bp().cycles += cycles
  280. unlock(&proflock)
  281. }
  282. // Go interface to profile data.
  283. // A StackRecord describes a single execution stack.
  284. type StackRecord struct {
  285. Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry
  286. }
  287. // Stack returns the stack trace associated with the record,
  288. // a prefix of r.Stack0.
  289. func (r *StackRecord) Stack() []uintptr {
  290. for i, v := range r.Stack0 {
  291. if v == 0 {
  292. return r.Stack0[0:i]
  293. }
  294. }
  295. return r.Stack0[0:]
  296. }
  297. // MemProfileRate controls the fraction of memory allocations
  298. // that are recorded and reported in the memory profile.
  299. // The profiler aims to sample an average of
  300. // one allocation per MemProfileRate bytes allocated.
  301. //
  302. // To include every allocated block in the profile, set MemProfileRate to 1.
  303. // To turn off profiling entirely, set MemProfileRate to 0.
  304. //
  305. // The tools that process the memory profiles assume that the
  306. // profile rate is constant across the lifetime of the program
  307. // and equal to the current value. Programs that change the
  308. // memory profiling rate should do so just once, as early as
  309. // possible in the execution of the program (for example,
  310. // at the beginning of main).
  311. var MemProfileRate int = 512 * 1024
  312. // A MemProfileRecord describes the live objects allocated
  313. // by a particular call sequence (stack trace).
  314. type MemProfileRecord struct {
  315. AllocBytes, FreeBytes int64 // number of bytes allocated, freed
  316. AllocObjects, FreeObjects int64 // number of objects allocated, freed
  317. Stack0 [32]uintptr // stack trace for this record; ends at first 0 entry
  318. }
  319. // InUseBytes returns the number of bytes in use (AllocBytes - FreeBytes).
  320. func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeBytes }
  321. // InUseObjects returns the number of objects in use (AllocObjects - FreeObjects).
  322. func (r *MemProfileRecord) InUseObjects() int64 {
  323. return r.AllocObjects - r.FreeObjects
  324. }
  325. // Stack returns the stack trace associated with the record,
  326. // a prefix of r.Stack0.
  327. func (r *MemProfileRecord) Stack() []uintptr {
  328. for i, v := range r.Stack0 {
  329. if v == 0 {
  330. return r.Stack0[0:i]
  331. }
  332. }
  333. return r.Stack0[0:]
  334. }
  335. // MemProfile returns n, the number of records in the current memory profile.
  336. // If len(p) >= n, MemProfile copies the profile into p and returns n, true.
  337. // If len(p) < n, MemProfile does not change p and returns n, false.
  338. //
  339. // If inuseZero is true, the profile includes allocation records
  340. // where r.AllocBytes > 0 but r.AllocBytes == r.FreeBytes.
  341. // These are sites where memory was allocated, but it has all
  342. // been released back to the runtime.
  343. //
  344. // Most clients should use the runtime/pprof package or
  345. // the testing package's -test.memprofile flag instead
  346. // of calling MemProfile directly.
  347. func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool) {
  348. lock(&proflock)
  349. clear := true
  350. for b := mbuckets; b != nil; b = b.allnext {
  351. mp := b.mp()
  352. if inuseZero || mp.alloc_bytes != mp.free_bytes {
  353. n++
  354. }
  355. if mp.allocs != 0 || mp.frees != 0 {
  356. clear = false
  357. }
  358. }
  359. if clear {
  360. // Absolutely no data, suggesting that a garbage collection
  361. // has not yet happened. In order to allow profiling when
  362. // garbage collection is disabled from the beginning of execution,
  363. // accumulate stats as if a GC just happened, and recount buckets.
  364. mprof_GC()
  365. mprof_GC()
  366. n = 0
  367. for b := mbuckets; b != nil; b = b.allnext {
  368. mp := b.mp()
  369. if inuseZero || mp.alloc_bytes != mp.free_bytes {
  370. n++
  371. }
  372. }
  373. }
  374. if n <= len(p) {
  375. ok = true
  376. idx := 0
  377. for b := mbuckets; b != nil; b = b.allnext {
  378. mp := b.mp()
  379. if inuseZero || mp.alloc_bytes != mp.free_bytes {
  380. record(&p[idx], b)
  381. idx++
  382. }
  383. }
  384. }
  385. unlock(&proflock)
  386. return
  387. }
  388. // Write b's data to r.
  389. func record(r *MemProfileRecord, b *bucket) {
  390. mp := b.mp()
  391. r.AllocBytes = int64(mp.alloc_bytes)
  392. r.FreeBytes = int64(mp.free_bytes)
  393. r.AllocObjects = int64(mp.allocs)
  394. r.FreeObjects = int64(mp.frees)
  395. copy(r.Stack0[:], b.stk())
  396. for i := int(b.nstk); i < len(r.Stack0); i++ {
  397. r.Stack0[i] = 0
  398. }
  399. }
  400. func iterate_memprof(fn func(*bucket, uintptr, *uintptr, uintptr, uintptr, uintptr)) {
  401. lock(&proflock)
  402. for b := mbuckets; b != nil; b = b.allnext {
  403. mp := b.mp()
  404. fn(b, uintptr(b.nstk), &b.stk()[0], b.size, mp.allocs, mp.frees)
  405. }
  406. unlock(&proflock)
  407. }
  408. // BlockProfileRecord describes blocking events originated
  409. // at a particular call sequence (stack trace).
  410. type BlockProfileRecord struct {
  411. Count int64
  412. Cycles int64
  413. StackRecord
  414. }
  415. // BlockProfile returns n, the number of records in the current blocking profile.
  416. // If len(p) >= n, BlockProfile copies the profile into p and returns n, true.
  417. // If len(p) < n, BlockProfile does not change p and returns n, false.
  418. //
  419. // Most clients should use the runtime/pprof package or
  420. // the testing package's -test.blockprofile flag instead
  421. // of calling BlockProfile directly.
  422. func BlockProfile(p []BlockProfileRecord) (n int, ok bool) {
  423. lock(&proflock)
  424. for b := bbuckets; b != nil; b = b.allnext {
  425. n++
  426. }
  427. if n <= len(p) {
  428. ok = true
  429. for b := bbuckets; b != nil; b = b.allnext {
  430. bp := b.bp()
  431. r := &p[0]
  432. r.Count = int64(bp.count)
  433. r.Cycles = int64(bp.cycles)
  434. i := copy(r.Stack0[:], b.stk())
  435. for ; i < len(r.Stack0); i++ {
  436. r.Stack0[i] = 0
  437. }
  438. p = p[1:]
  439. }
  440. }
  441. unlock(&proflock)
  442. return
  443. }
  444. // ThreadCreateProfile returns n, the number of records in the thread creation profile.
  445. // If len(p) >= n, ThreadCreateProfile copies the profile into p and returns n, true.
  446. // If len(p) < n, ThreadCreateProfile does not change p and returns n, false.
  447. //
  448. // Most clients should use the runtime/pprof package instead
  449. // of calling ThreadCreateProfile directly.
  450. func ThreadCreateProfile(p []StackRecord) (n int, ok bool) {
  451. first := (*m)(atomicloadp(unsafe.Pointer(&allm)))
  452. for mp := first; mp != nil; mp = mp.alllink {
  453. n++
  454. }
  455. if n <= len(p) {
  456. ok = true
  457. i := 0
  458. for mp := first; mp != nil; mp = mp.alllink {
  459. for s := range mp.createstack {
  460. p[i].Stack0[s] = uintptr(mp.createstack[s])
  461. }
  462. i++
  463. }
  464. }
  465. return
  466. }
  467. var allgs []*g // proc.c
  468. // GoroutineProfile returns n, the number of records in the active goroutine stack profile.
  469. // If len(p) >= n, GoroutineProfile copies the profile into p and returns n, true.
  470. // If len(p) < n, GoroutineProfile does not change p and returns n, false.
  471. //
  472. // Most clients should use the runtime/pprof package instead
  473. // of calling GoroutineProfile directly.
  474. func GoroutineProfile(p []StackRecord) (n int, ok bool) {
  475. n = NumGoroutine()
  476. if n <= len(p) {
  477. gp := getg()
  478. semacquire(&worldsema, false)
  479. gp.m.gcing = 1
  480. onM(stoptheworld)
  481. n = NumGoroutine()
  482. if n <= len(p) {
  483. ok = true
  484. r := p
  485. sp := getcallersp(unsafe.Pointer(&p))
  486. pc := getcallerpc(unsafe.Pointer(&p))
  487. onM(func() {
  488. saveg(pc, sp, gp, &r[0])
  489. })
  490. r = r[1:]
  491. for _, gp1 := range allgs {
  492. if gp1 == gp || readgstatus(gp1) == _Gdead {
  493. continue
  494. }
  495. saveg(^uintptr(0), ^uintptr(0), gp1, &r[0])
  496. r = r[1:]
  497. }
  498. }
  499. gp.m.gcing = 0
  500. semrelease(&worldsema)
  501. onM(starttheworld)
  502. }
  503. return n, ok
  504. }
  505. func saveg(pc, sp uintptr, gp *g, r *StackRecord) {
  506. n := gentraceback(pc, sp, 0, gp, 0, &r.Stack0[0], len(r.Stack0), nil, nil, 0)
  507. if n < len(r.Stack0) {
  508. r.Stack0[n] = 0
  509. }
  510. }
  511. // Stack formats a stack trace of the calling goroutine into buf
  512. // and returns the number of bytes written to buf.
  513. // If all is true, Stack formats stack traces of all other goroutines
  514. // into buf after the trace for the current goroutine.
  515. func Stack(buf []byte, all bool) int {
  516. if all {
  517. semacquire(&worldsema, false)
  518. gp := getg()
  519. gp.m.gcing = 1
  520. onM(stoptheworld)
  521. }
  522. n := 0
  523. if len(buf) > 0 {
  524. gp := getg()
  525. sp := getcallersp(unsafe.Pointer(&buf))
  526. pc := getcallerpc(unsafe.Pointer(&buf))
  527. onM(func() {
  528. g0 := getg()
  529. g0.writebuf = buf[0:0:len(buf)]
  530. goroutineheader(gp)
  531. traceback(pc, sp, 0, gp)
  532. if all {
  533. tracebackothers(gp)
  534. }
  535. n = len(g0.writebuf)
  536. g0.writebuf = nil
  537. })
  538. }
  539. if all {
  540. gp := getg()
  541. gp.m.gcing = 0
  542. semrelease(&worldsema)
  543. onM(starttheworld)
  544. }
  545. return n
  546. }
  547. // Tracing of alloc/free/gc.
  548. var tracelock mutex
  549. func tracealloc(p unsafe.Pointer, size uintptr, typ *_type) {
  550. lock(&tracelock)
  551. gp := getg()
  552. gp.m.traceback = 2
  553. if typ == nil {
  554. print("tracealloc(", p, ", ", hex(size), ")\n")
  555. } else {
  556. print("tracealloc(", p, ", ", hex(size), ", ", *typ._string, ")\n")
  557. }
  558. if gp.m.curg == nil || gp == gp.m.curg {
  559. goroutineheader(gp)
  560. pc := getcallerpc(unsafe.Pointer(&p))
  561. sp := getcallersp(unsafe.Pointer(&p))
  562. onM(func() {
  563. traceback(pc, sp, 0, gp)
  564. })
  565. } else {
  566. goroutineheader(gp.m.curg)
  567. traceback(^uintptr(0), ^uintptr(0), 0, gp.m.curg)
  568. }
  569. print("\n")
  570. gp.m.traceback = 0
  571. unlock(&tracelock)
  572. }
  573. func tracefree(p unsafe.Pointer, size uintptr) {
  574. lock(&tracelock)
  575. gp := getg()
  576. gp.m.traceback = 2
  577. print("tracefree(", p, ", ", hex(size), ")\n")
  578. goroutineheader(gp)
  579. pc := getcallerpc(unsafe.Pointer(&p))
  580. sp := getcallersp(unsafe.Pointer(&p))
  581. onM(func() {
  582. traceback(pc, sp, 0, gp)
  583. })
  584. print("\n")
  585. gp.m.traceback = 0
  586. unlock(&tracelock)
  587. }
  588. func tracegc() {
  589. lock(&tracelock)
  590. gp := getg()
  591. gp.m.traceback = 2
  592. print("tracegc()\n")
  593. // running on m->g0 stack; show all non-g0 goroutines
  594. tracebackothers(gp)
  595. print("end tracegc\n")
  596. print("\n")
  597. gp.m.traceback = 0
  598. unlock(&tracelock)
  599. }