-
Notifications
You must be signed in to change notification settings - Fork 202
feature: supported to measure the distribution of the VFS read/write … #36
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
Open
membphis
wants to merge
5
commits into
openresty:master
Choose a base branch
from
membphis:disk-io-blocking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c7d9b9
feature: supported to measure the distribution of the VFS read/write …
membphis 52b11d6
change: code style.
membphis 3501b19
feature: supported to specify the master process and monitor all the …
membphis 8614e3b
doc: added doc for `disk-io-blocking-vfs`.
membphis 76837d5
change: renamed the script from `disk-io-blocking-vfs` to `file-io-bl…
membphis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,56 @@ | ||
| #!/usr/bin/env stap++ | ||
|
|
||
| # Measure the distribution of the VFS read/write latency. | ||
|
|
||
| global begin, stats, found | ||
|
|
||
| probe syscall.lseek, syscall.renameat, syscall.open, syscall.close, | ||
| syscall.sendfile*, vfs.read*, vfs.write*, syscall.*stat*, | ||
| syscall.unlink, syscall.mkdir, syscall.rmdir | ||
| { | ||
| if ($^pid_ok) { | ||
| begin[pid()] = gettimeofday_us() | ||
| } | ||
| } | ||
|
|
||
| probe syscall.lseek.return, syscall.renameat.return, syscall.open.return, | ||
| syscall.close.return, syscall.sendfile*.return, vfs.read*.return, | ||
| vfs.write*.return, syscall.*stat*.return, syscall.unlink.return, | ||
| syscall.mkdir.return, syscall.rmdir.return | ||
| { | ||
| if ($^pid_ok && begin[pid()] > 0) { | ||
| stats[pid()] <<< gettimeofday_us() - begin[pid()] | ||
| found = 1 | ||
| } | ||
| } | ||
|
|
||
| %( "$^arg_time :default()" != "" %? | ||
| probe timer.s($^arg_time) { | ||
| exit() | ||
| } | ||
| %) | ||
|
|
||
| probe end { | ||
|
|
||
| if (!found) { | ||
| printf("No samples observed so far.\n"); | ||
|
|
||
| } else { | ||
| printf("Distribution of file IO blocking latencies (in microseconds)\n") | ||
|
|
||
| foreach (pid in stats) { | ||
| printf("pid %d:\n", pid) | ||
| printf("max/avg/min: %d/%d/%d\n", @max(stats[pid]), @avg(stats[pid]), @min(stats[pid])) | ||
| print(@hist_log(stats[pid])) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| probe begin { | ||
| printf("Start tracing ($^target) ($^exec_path)...\n") | ||
| %( "$^arg_time :default()" != "" %? | ||
| printf("Please wait for $^arg_time seconds...\n\n") | ||
| %: | ||
| printf("Hit Ctrl-C to end.\n\n") | ||
| %) | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,72 +1,115 @@ | ||
| #!/usr/bin/env stap++ | ||
|
|
||
| global begin_times | ||
| global latencies | ||
| global method_id | ||
|
|
||
| probe @pfunc(ngx_http_handler) { | ||
| if (pid() == target() && $r == $r->main) { | ||
| if ("$^arg_method :default()" != "") { | ||
| if (method_id == 0) { | ||
| if ($r->method_name->len > 0) { | ||
| method = user_string_n($r->method_name->data, $r->method_name->len) | ||
| //printf("found method %s\n", method) | ||
| if (method == "$^arg_method") { | ||
| method_id = $r->method | ||
| //printf("found method id %d\n", method_id) | ||
| } | ||
| @use nginx.request | ||
|
|
||
| global begin_times, pre_end_time | ||
| global latencies, req_latencies | ||
| global init_conns | ||
| global pid, matched_r, matched | ||
| global log_r | ||
|
|
||
| probe @pfunc(ngx_http_create_request) | ||
| { | ||
| if ($^pid_ok) { | ||
| init_conns[$c, pid()] = gettimeofday_us() | ||
| } | ||
| } | ||
|
|
||
| probe @pfunc(ngx_http_close_connection) { | ||
| delete init_conns[$c, pid()] | ||
| } | ||
|
|
||
| probe @pfunc(ngx_http_process_request) { | ||
| pid = pid() | ||
|
|
||
| if ($^pid_ok) { | ||
| begin_time = init_conns[$r->connection, pid()] | ||
| if (begin_time) { | ||
| matched_r[$r] = 1 | ||
| %( "$^arg_uri :default()" == "" %? | ||
| %: | ||
| if (ngx_req_uri($r) != "$^arg_uri") { | ||
| delete matched_r[$r] | ||
| } | ||
| } | ||
| %) | ||
|
|
||
| if (method_id && method_id == $r->method) { | ||
| begin_times[$r] = gettimeofday_us() | ||
| } | ||
| %( "$^arg_method :default()" == "" %? | ||
| %: | ||
| if (ngx_req_method($r) != "$^arg_method") { | ||
| delete matched_r[$r] | ||
| } | ||
| %) | ||
|
|
||
| if (matched_r[$r]) { | ||
| begin_times[$r] = begin_time | ||
|
|
||
| } else { | ||
| begin_times[$r] = gettimeofday_us() | ||
| if (pre_end_time) { | ||
| req_latencies[pid] <<< begin_times[$r] - pre_end_time | ||
| pre_end_time = 0 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| probe @pfunc(ngx_http_log_request) { | ||
| if (pid() == target()) { | ||
| begin = begin_times[$r] | ||
| if (begin) { | ||
| latencies <<< gettimeofday_us() - begin | ||
| delete begin_times[$r] | ||
| if ($^pid_ok && matched_r[$r]) { | ||
| log_r = $r | ||
| } | ||
| } | ||
|
|
||
| probe @pfunc(ngx_http_log_request).return { | ||
| if ($^pid_ok && log_r) { | ||
| begin_time = begin_times[log_r] | ||
| if (begin_time) { | ||
| pre_end_time = gettimeofday_us() | ||
| latencies[pid()] <<< pre_end_time - begin_time | ||
| matched = 1 | ||
| delete begin_times[log_r] | ||
| } | ||
|
|
||
| delete matched_r[log_r] | ||
| log_r = 0 | ||
| } | ||
| } | ||
|
|
||
| probe begin { | ||
| printf("Start tracing process %d ($^exec_path)...\n", target()) | ||
| printf("Start tracing process ($^target) ($^exec_path)...\n") | ||
| %( "$^arg_time :default()" != "" %? | ||
| printf("Please wait for $^arg_time seconds...\n") | ||
| %: | ||
| printf("Hit Ctrl-C to end.\n") | ||
| %) | ||
|
|
||
| if ("$^arg_method" != "") { | ||
| printf("(Tracing only $^arg_method request methods)\n") | ||
| } | ||
| } | ||
|
|
||
| %( "$^arg_time" != "" %? | ||
| %( "$^arg_time :default()" != "" %? | ||
| probe timer.s($^arg_time) { | ||
| exit() | ||
| } | ||
| %) | ||
|
|
||
| probe end { | ||
| count = @count(latencies) | ||
| if (count == 0) { | ||
| if (!matched) { | ||
| printf("\nNo samples found so far.\n") | ||
|
|
||
| } else { | ||
| printf("\nDistribution of the main request latencies (in microseconds) for %d samples:\n", | ||
| count) | ||
| printf("(min/avg/max: %d/%d/%d)\n", @min(latencies), @avg(latencies), | ||
| @max(latencies)) | ||
| print(@hist_log(latencies)) | ||
|
|
||
| foreach(pid in latencies) { | ||
| count = @count(latencies[pid]) | ||
| printf("\nDistribution of the request latencies (in microseconds) for %d samples:\n", count) | ||
| printf("(pid: %d min/avg/max: %d/%d/%d)\n", pid, @min(latencies[pid]), @avg(latencies[pid]), | ||
| @max(latencies[pid])) | ||
| print(@hist_log(latencies[pid])) | ||
| print("\n") | ||
| } | ||
|
|
||
| foreach(pid in req_latencies) { | ||
| count = @count(req_latencies[pid]) | ||
| printf("\nDistribution of latencies between different requests (in microseconds) for %d samples:\n", | ||
| count) | ||
| printf("(pid: %d min/avg/max: %d/%d/%d)\n", pid, @min(req_latencies[pid]), | ||
| @avg(req_latencies[pid]), @max(req_latencies[pid])) | ||
| print(@hist_log(req_latencies[pid])) | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool name is too verbose.
vfsmeansvirtual file system, which already impliesdisk I/O. Also, you are actually testing file IO instead of disk IO since there is no way to know if it indeed touches the disk device on the VFS level.