Number of OS threads used by Go runtime

715 views
Skip to first unread message

yuri.sh...@gmail.com

unread,
Apr 6, 2017, 11:37:55 AM4/6/17
to golang-nuts
Hi all!

Is there any way to count number of OS threads used by Go runtime programmatically (ie without using bash with top/ps and others)?

--
Best regards, Yuri

Ian Lance Taylor

unread,
Apr 6, 2017, 2:15:02 PM4/6/17
to yuri.sh...@gmail.com, golang-nuts
On Thu, Apr 6, 2017 at 3:07 AM, <yuri.sh...@gmail.com> wrote:
>
> Is there any way to count number of OS threads used by Go runtime
> programmatically (ie without using bash with top/ps and others)?

Not at present.

Perhaps it could be added to the SchedStats proposal
(https://golang.org/issue/15490).

Ian

Uli Kunitz

unread,
Apr 6, 2017, 2:18:04 PM4/6/17
to golang-nuts
I suggest to give n, _ := runtime.ThreadCreateProfile(nil) a try. 

Ian Lance Taylor

unread,
Apr 6, 2017, 3:09:55 PM4/6/17
to Uli Kunitz, golang-nuts
On Thu, Apr 6, 2017 at 11:18 AM, Uli Kunitz <uli.k...@gmail.com> wrote:
> I suggest to give n, _ := runtime.ThreadCreateProfile(nil) a try.

Good point, yes, that should work.

Ian

> On Thursday, April 6, 2017 at 5:37:55 PM UTC+2, Юрий Шахматов wrote:
>>
>> Hi all!
>>
>> Is there any way to count number of OS threads used by Go runtime
>> programmatically (ie without using bash with top/ps and others)?
>>
>> --
>> Best regards, Yuri
>
> --
> 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 golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

C Banning

unread,
Apr 7, 2017, 6:11:03 AM4/7/17
to golang-nuts

Val

unread,
Apr 12, 2017, 4:36:09 AM4/12/17
to golang-nuts


For visualization of this value over time, you may use  go tool trace
https://making.pusher.com/go-tool-trace/

HTH,
Val


On Thursday, April 6, 2017 at 5:37:55 PM UTC+2, Юрий Шахматов wrote:
Reply all
Reply to author
Forward
0 new messages