Skip to content

Commit

Permalink
Make the timestamp of the profiling files readable (#434)
Browse files Browse the repository at this point in the history
Signed-off-by: Daxin Wang <daxinwang@harmonycloud.cn>
  • Loading branch information
dxsup authored Jan 10, 2023
1 parent ca21eb7 commit cc7612a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### New features

### Enhancements
- Rename the camera profiling file to make the timestamp of the profiling files readable. ([#434](https://github.com/KindlingProject/kindling/pull/434))
- When using the file writer in `cameraexporter`, we rotate files in chronological order now and rotate half of files one time. ([#420](https://github.com/KindlingProject/kindling/pull/420))
- Support to identify the MySQL protocol with statements `commit` and `set`. ([#417](https://github.com/KindlingProject/kindling/pull/417))

Expand Down
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)
}
}
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func getFileName(protocol string, contentKey string, timestamp uint64, isServer
isServerString = "false"
}
encodedContent := base64.URLEncoding.EncodeToString([]byte(contentKey))
return protocol + "_" + encodedContent + "_" + strconv.FormatUint(timestamp, 10) + "_" + isServerString
return getDateString(int64(timestamp)) + "_" + protocol + "_" + encodedContent + "_" + isServerString
}

func (fw *fileWriter) writeTrace(group *model.DataGroup) {
Expand Down

0 comments on commit cc7612a

Please sign in to comment.