Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add func BdevGetIostat #192

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/spdk/client/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,27 @@

return deleted, json.Unmarshal(cmdOutput, &deleted)
}

// BdevGetIostat get I/O statistics of block devices (bdevs).
//
// "name": Optional. If this is not specified, the function will list all block devices.
//
// "per_channel": Optional. Display per channel data for specified block device.
func (c *Client) BdevGetIostat(name string, perChannel bool) (resp *spdktypes.BdevIostatResponse, err error) {
req := spdktypes.BdevIostatRequest{
Name: name,
PerChannel: perChannel,
}

cmdOutput, err := c.jsonCli.SendCommand("bdev_get_iostat", req)
if err != nil {
return nil, err
}

Check warning on line 1331 in pkg/spdk/client/basic.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L1322-L1331

Added lines #L1322 - L1331 were not covered by tests

resp = &spdktypes.BdevIostatResponse{}
if err := json.Unmarshal(cmdOutput, resp); err != nil {
return nil, errors.Wrap(err, "failed to parse bdev_get_iostat response")
}

Check warning on line 1336 in pkg/spdk/client/basic.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L1333-L1336

Added lines #L1333 - L1336 were not covered by tests

return resp, nil

Check warning on line 1338 in pkg/spdk/client/basic.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L1338

Added line #L1338 was not covered by tests
}
27 changes: 27 additions & 0 deletions pkg/spdk/types/bdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,30 @@ type BdevLvolFragmap struct {
NumAllocatedClusters uint64 `json:"num_allocated_clusters"`
Fragmap string `json:"fragmap"`
}

type BdevIostatRequest struct {
Name string `json:"name,omitempty"`
PerChannel bool `json:"per_channel,omitempty"`
}

type BdevIostatResponse struct {
TickRate uint64 `json:"tick_rate"`
Ticks uint64 `json:"ticks"`
Bdevs []BdevStats `json:"bdevs"`
}

type BdevStats struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name string `json:"name"`
BytesRead uint64 `json:"bytes_read"`
NumReadOps uint64 `json:"num_read_ops"`
BytesWritten uint64 `json:"bytes_written"`
NumWriteOps uint64 `json:"num_write_ops"`
BytesUnmapped uint64 `json:"bytes_unmapped"`
NumUnmapOps uint64 `json:"num_unmap_ops"`
ReadLatencyTicks uint64 `json:"read_latency_ticks"`
WriteLatencyTicks uint64 `json:"write_latency_ticks"`
UnmapLatencyTicks uint64 `json:"unmap_latency_ticks"`
QueueDepth uint64 `json:"queue_depth"`
IoTime uint64 `json:"io_time"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hookak What is io_time and weighted_io_time in the stat?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekbit weighted_io_time is the sum of all I/O request execution times, calculated as I/O execution time × queue depth.
This link will help with understanding(https://github.com/spdk/spdk/blob/e01cb43b8578f9155d07a9bc6eee4e70a3af96b0/include/spdk/bdev.h#L1052-L1068)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Thank you @hookak.

WeightedIoTime uint64 `json:"weighted_io_time"`
}
Loading