tools: acrntrace: save trace data file under current dir by default

Current implementation save trace data files on tmpfs by default, acrntrace
would use up all the physical mem, which can affect system functioning.
This commit changes default location for trace data file to current dir, and
removes the codes for space reservation, which is not necessary.

Signed-off-by: Yan, Like <like.yan@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Reviewed-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
Yan, Like 2018-07-20 15:24:00 +08:00 committed by lijinxia
parent 3abfdbab72
commit 3d6ff0e5f4
4 changed files with 10 additions and 42 deletions

View File

@ -13,7 +13,7 @@ Usage
*****
The ``acrntrace`` tool runs on the Service OS (SOS) to capture trace data and
output to trace file under ``/tmp/acrntrace`` with raw (binary) data format.
output to trace file under ``./acrntrace`` with raw (binary) data format.
Options:
@ -96,7 +96,7 @@ data to your linux system, and running the analysis tool.
will exit automatically when the free storage space on the disk is less than
reserved space. Reserved space on the disk is configurable through '-r'.
Trace files are created under ``/tmp/acrntrace/``, with a
Trace files are created under ``./acrntrace/``, with a
date-time-based directory name such as ``20171115-101605``
#. When done, stop a running ``acrntrace``, with:
@ -120,7 +120,7 @@ data to your linux system, and running the analysis tool.
.. code-block:: none
# scp -r /tmp/acrntrace/20171115-101605/ \
# scp -r ./acrntrace/20171115-101605/ \
username@hostname:/home/username/trace_data
Replace username and hostname with appropriate values.

View File

@ -22,9 +22,6 @@
#include "acrntrace.h"
/* default minimal amount free space (in MB) left on the disk */
static uint64_t disk_reserved = 512;
#define TIMER_ID (128)
static uint32_t timeout = 0;
@ -47,8 +44,6 @@ static void display_usage(void)
"[Usage] acrntrace [-i] [period in msec] [-ch]\n\n"
"[Options]\n"
"\t-h: print this message\n"
"\t-r: minimal amount (in MB) of free space kept on the disk\n"
"\t before acrntrace stops\n"
"\t-i: period_in_ms: specify polling interval [1-999]\n"
"\t-t: max time to capture trace data (in second)\n"
"\t-c: clear the buffered old data\n");
@ -109,15 +104,6 @@ static int parse_opt(int argc, char *argv[])
period = ret * 1000;
pr_dbg("Period is %lu\n", period);
break;
case 'r':
ret = atoi(optarg);
if (ret <=0) {
pr_err("'-r' require integer greater than 0\n");
return -EINVAL;
}
disk_reserved = ret;
pr_dbg("Keeping %dMB of space on the disk\n", ret);
break;
case 't':
ret = atoi(optarg);
if (ret <= 0) {
@ -186,7 +172,6 @@ static int create_trace_file_dir(char *dir)
pr_info("start tracing at %s\n", time_str);
/* Pre-condition: Make sure tmpfs is mounted on /tmp */
if (stat(TRACE_FILE_ROOT, &st)) {
err = mkdir(TRACE_FILE_ROOT, 0644);
if (err) {
@ -234,24 +219,6 @@ static void reader_fn(param_t * param)
while (1) {
do {
/* Check that filesystem has enough space */
if (fstatvfs(fd, &stat)) {
printf("Fail to get vfs stat.\n");
exiting = 1;
exit(EXIT_FAILURE);
}
freespace = stat.f_frsize * (uint64_t)stat.f_bfree;
freespace >>= 20; /* Convert to MB */
if (freespace <= disk_reserved) {
printf("Disk space limit reached (free space:"
"%luMB, limit %luMB).\n",
freespace, disk_reserved);
exiting = 1;
exit(EXIT_FAILURE);
}
ret = sbuf_write(fd, sbuf);
} while (ret > 0);

View File

@ -17,9 +17,9 @@
#define MMAP_SIZE ((TRACE_ELEMENT_SIZE * TRACE_ELEMENT_NUM \
+ PAGE_SIZE - 1) & PAGE_MASK)
*/
#define TRACE_FILE_NAME_LEN 36
#define TRACE_FILE_DIR_LEN (TRACE_FILE_NAME_LEN - 2)
#define TRACE_FILE_ROOT "/tmp/acrntrace/"
#define TRACE_FILE_NAME_LEN 32
#define TRACE_FILE_DIR_LEN (TRACE_FILE_NAME_LEN - 3)
#define TRACE_FILE_ROOT "acrntrace/"
#define DEV_PATH_LEN 18
#define TIME_STR_LEN 16
#define CMD_MAX_LEN 48

View File

@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdbool.h>
#include "sbuf.h"
#include <errno.h>
static inline bool sbuf_is_empty(shared_buf_t *sbuf)
{
@ -59,9 +60,9 @@ int sbuf_write(int fd, shared_buf_t *sbuf)
start = (void *)sbuf + SBUF_HEAD_SIZE + sbuf->head;
written = write(fd, start, sbuf->ele_size);
if ( written != sbuf->ele_size) {
printf("Failed to write. Expect written size %d, returned %d\n",
sbuf->ele_size, written);
if (written != sbuf->ele_size) {
printf("Failed to write: ret %d (ele_size %d), errno %d\n",
written, sbuf->ele_size, (written == -1) ? errno : 0);
return -1;
}