如何将 vmstat 的输出重定向到 Android 操作系统中的文件?
我通过 adb shell 命令连接到我的 root 手机,然后运行 vmstat命令来查看各种系统资源。是 有一种方法可以将 vmstat 的输出重定向到文件。我尝试过:
vmstat > /sdcard/vmstat_output.txt
但它不起作用..它创建了文件,但里面没有数据..
有什么想法吗?
I connect to my rooted phone through adb shell command and I run
the vmstat command so as to watch various system resources. Is
there a way to redirect vmstat's output to a file. I tried:
vmstat > /sdcard/vmstat_output.txt
but it doesn't work.. It creates the file but there is no data inside..
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 vmstat 的输出在重定向到文件时是块缓冲的。因此 vmstat 在将数据刷新到文件之前必须写入一个块的数据,如果在它写入足够的数据之前中断它,那么文件就是空的。如果你等待足够长的时间,你应该会得到一些输出(对我有用)。
您可以在使用“-n”标志写入几行后让 vmstat 终止自身(刷新数据),但该功能似乎已损坏。
我相信 /proc/vmstat、/proc/stat 和 /proc/meminfo 具有相同的信息,只是格式不像 vmstat 那样好。
I think the output from vmstat is block-buffered when redirected to a file. So vmstat would have to write a blocks worth of data before it is flushed to the file, and if you interrupt it before it has written enough then the file is empty. If you wait long enough you should have some output (worked for me).
You could have vmstat terminate itself (flushing the data) after writing a few lines with the "-n " flag, but that feature seems to be broken.
/proc/vmstat, /proc/stat, and /proc/meminfo have the same information I believe, just not formatted nicely like with vmstat.
好的,我解决了问题。我从
对在 print_line 命令之后(第 134 行)。然后,我交叉编译了 vmstat.c
agcc:
和通过 adb 将文件放入 /sdcard/:
现在重定向工作了
完美,因为每次调用 print_line 后,数据都会刷新到文件中。正如马克·波哈姆斯提到的,
问题是 vmstat 是一个块缓冲命令,这意味着缓冲区
必须先填充数据,然后将这些数据刷新到文件中。
非常感谢马克! :)
Ok, I fixed the problem. I download the source from here and I added one extra line:
right after the print_line command (line: 134). Then, I cross-compiled the vmstat.c with
agcc:
and put the file to the /sdcard/ through the adb:
Now the redirection works
perfectly, as after every print_line call, the data are flushed to the file. As Mark Polhamus mentioned,
the problem was the fact that vmstat is a block-buffered command, which means that a buffer
has to be filled with data first and then this data will be flushed to the file..
Thank you very much Mark! :)
我通常通过在
adb
上的 -s 开关的帮助下将其直接重定向到我的本地计算机,您可以选择设备,从而同时将多个连接的设备记录到单独的日志中。
I usually redirect it directly to my local machine via
with help of the -s switch on
adb
you can select the device and thus log several connected devices simultaneously to separate logs.