-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the timestamp of the profiling files readable (#434)
Signed-off-by: Daxin Wang <daxinwang@harmonycloud.cn>
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
collector/pkg/component/consumer/exporter/cameraexporter/datehelper.go
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,24 @@ | ||
package cameraexporter | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func getDateString(timestamp int64) string { | ||
timeUnix := time.Unix(0, timestamp) | ||
year, month, day := timeUnix.Date() | ||
hour, minute, second := timeUnix.Clock() | ||
nano := timestamp % 1e9 | ||
return dateToString(year) + dateToString(int(month)) + dateToString(day) + | ||
dateToString(hour) + dateToString(minute) + dateToString(second) + | ||
"." + dateToString(int(nano)) | ||
} | ||
|
||
func dateToString(date int) string { | ||
if date >= 0 && date <= 9 { | ||
return "0" + strconv.FormatInt(int64(date), 10) | ||
} else { | ||
return strconv.FormatInt(int64(date), 10) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
collector/pkg/component/consumer/exporter/cameraexporter/datehelper_test.go
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,13 @@ | ||
package cameraexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetDateString(t *testing.T) { | ||
nanoseconds := 1672887314101975422 | ||
dateString := getDateString(int64(nanoseconds)) | ||
assert.Equal(t, "20230105105514.101975422", dateString) | ||
} |
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