-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh boot time #1616
Refresh boot time #1616
Conversation
This commit adds the RefreshBootTimeCache function, allowing users to manually refresh the cached boot time if they are using the `enableBootTimeCache` feature.
This commit adds the RefreshBootTimeCache function, allowing users to manually refresh the cached boot time if they are using the `enableBootTimeCache` feature.
796962c
to
f6350ce
Compare
I think the same could be accomplished with the following code on a library user side. I don't think it is necessary to add a new API. host.EnableBootTimeCache(false)
defer host.EnableBootTimeCache(true)
BootTimeWithContext(ctx) |
That would be better if it was possible, but BootTimeWithContext is internal. So I don't see any way on the user side to only read boot time once. |
I will work on an alternative PR that instead factors boot time into the common package and provides entrypoints so that your suggestion is possible. |
package main
import (
"context"
"fmt"
"github.com/shirou/gopsutil/v3/host"
)
func main() {
host.EnableBootTimeCache(false)
defer host.EnableBootTimeCache(true)
fmt.Println(host.BootTimeWithContext(context.Background()))
} |
Closing in favour of #1618 |
Ah okay so using the |
This PR adds a function to
process
andhost
to manually refresh the cached boot time value. This is very helpful in scenarios where you are reading all the processes on the system at a given time, want the performance gains of using the boot time cache, but want to update the cached boot time when you read all the processes.