summaryrefslogtreecommitdiff
path: root/timer.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-15 19:24:48 -0600
committerJeff Carr <[email protected]>2024-01-15 19:24:48 -0600
commitfdac7e7b8944d51b8207c1797edd0be9450de7b8 (patch)
tree9e762c05ea6f716dc9434dae1e852630bd6c0ec5 /timer.go
parent94aa368cff322e667156571638a45bd3117a2739 (diff)
restore the files after garbage collectionv0.5.5
hopefully this actually is a valid git repo
Diffstat (limited to 'timer.go')
-rw-r--r--timer.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/timer.go b/timer.go
new file mode 100644
index 0000000..17130f3
--- /dev/null
+++ b/timer.go
@@ -0,0 +1,36 @@
+package linuxstatus
+
+import (
+ "time"
+ "sort"
+ "strings"
+)
+
+// timeFunction takes a function as an argument and returns the execution time.
+func timeFunction(f func()) time.Duration {
+ startTime := time.Now() // Record the start time
+ f() // Execute the function
+ return time.Since(startTime) // Calculate the elapsed time
+}
+
+// sortLines takes a string, splits it on newlines, sorts the lines,
+// and rejoins them with newlines.
+func sortLines(input string) string {
+ lines := strings.Split(input, "\n")
+
+ // Trim leading and trailing whitespace from each line
+ for i, line := range lines {
+ lines[i] = strings.TrimSpace(line)
+ }
+
+ sort.Strings(lines)
+ tmp := strings.Join(lines, "\n")
+ tmp = strings.TrimLeft(tmp, "\n")
+ tmp = strings.TrimRight(tmp, "\n")
+ return tmp
+}
+
+func (ls *LinuxStatus) SetSpeedActual(s string) {
+ if ! ls.Ready() {return}
+ ls.speedActual.Set(s)
+}