-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* libbeat: add CPU usage to metrics * Add both percentage and normalized percentage of CPU. * Move Round function to common. * turn off crosscompile tests
- Loading branch information
Showing
27 changed files
with
425 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package common | ||
|
||
import "math" | ||
|
||
// DefaultDecimalPlacesCount is the default number of decimal places | ||
const DefaultDecimalPlacesCount = 4 | ||
|
||
// Round rounds the given float64 value and ensures that it has a maximum of | ||
// "precision" decimal places. | ||
func Round(val float64, precision int64) (newVal float64) { | ||
var round float64 | ||
pow := math.Pow(10, float64(precision)) | ||
digit := pow * val | ||
_, div := math.Modf(digit) | ||
if div >= 0.5 { | ||
round = math.Ceil(digit) | ||
} else { | ||
round = math.Floor(digit) | ||
} | ||
newVal = round / pow | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRound(t *testing.T) { | ||
assert.EqualValues(t, 0.5, Round(0.5, DefaultDecimalPlacesCount)) | ||
assert.EqualValues(t, 0.5, Round(0.50004, DefaultDecimalPlacesCount)) | ||
assert.EqualValues(t, 0.5001, Round(0.50005, DefaultDecimalPlacesCount)) | ||
|
||
assert.EqualValues(t, 1234.5, Round(1234.5, DefaultDecimalPlacesCount)) | ||
assert.EqualValues(t, 1234.5, Round(1234.50004, DefaultDecimalPlacesCount)) | ||
assert.EqualValues(t, 1234.5001, Round(1234.50005, DefaultDecimalPlacesCount)) | ||
} |
Oops, something went wrong.