summaryrefslogtreecommitdiff
path: root/linuxstatus/timer.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 05:24:11 -0600
committerJeff Carr <[email protected]>2024-01-06 05:24:11 -0600
commit3457aefa86ccc9bc6c4eda059e48ebcb8830b410 (patch)
tree525dca4d9ec74d26282521148cd4918d85081e9b /linuxstatus/timer.go
parentd2fb88cd584b8e7e60cb6315d9fb8d0d6ceac22f (diff)
add LinuxStatus()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'linuxstatus/timer.go')
-rw-r--r--linuxstatus/timer.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/linuxstatus/timer.go b/linuxstatus/timer.go
new file mode 100644
index 0000000..cd82f49
--- /dev/null
+++ b/linuxstatus/timer.go
@@ -0,0 +1,31 @@
+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
+}