aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--trace-cmd.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/trace-cmd.c b/trace-cmd.c
index 49110f3..e85b550 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -56,6 +56,8 @@ static int use_tcp;
56 56
57static unsigned int page_size; 57static unsigned int page_size;
58 58
59static int buffer_size;
60
59static const char *output_file = "trace.dat"; 61static const char *output_file = "trace.dat";
60 62
61static int latency; 63static int latency;
@@ -1239,6 +1241,32 @@ static void add_func(struct func_list **list, const char *func)
1239 *list = item; 1241 *list = item;
1240} 1242}
1241 1243
1244void set_buffer_size(void)
1245{
1246 char buf[BUFSIZ];
1247 char *path;
1248 int ret;
1249 int fd;
1250
1251 if (!buffer_size)
1252 return;
1253
1254 if (buffer_size < 0)
1255 die("buffer size must be positive");
1256
1257 snprintf(buf, BUFSIZ, "%d", buffer_size);
1258
1259 path = get_tracing_file("buffer_size_kb");
1260 fd = open(path, O_WRONLY);
1261 if (fd < 0)
1262 die("can't open %s", path);
1263
1264 ret = write(fd, buf, strlen(buf));
1265 if (ret < 0)
1266 warning("Can't write to %s", path);
1267 close(fd);
1268}
1269
1242void usage(char **argv) 1270void usage(char **argv)
1243{ 1271{
1244 char *arg = argv[0]; 1272 char *arg = argv[0];
@@ -1253,7 +1281,7 @@ void usage(char **argv)
1253 "usage:\n" 1281 "usage:\n"
1254 " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n" 1282 " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n"
1255 " [-s usecs][-O option ][-l func][-g func][-n func]\n" 1283 " [-s usecs][-O option ][-l func][-g func][-n func]\n"
1256 " [-P pid][-N host:port][-t][command ...]\n" 1284 " [-P pid][-N host:port][-t][-b size][command ...]\n"
1257 " -e run command with event enabled\n" 1285 " -e run command with event enabled\n"
1258 " -f filter for previous -e event\n" 1286 " -f filter for previous -e event\n"
1259 " -p run command with plugin enabled\n" 1287 " -p run command with plugin enabled\n"
@@ -1269,6 +1297,7 @@ void usage(char **argv)
1269 " -s sleep interval between recording (in usecs) [default: 1000]\n" 1297 " -s sleep interval between recording (in usecs) [default: 1000]\n"
1270 " -N host:port to connect to (see listen)\n" 1298 " -N host:port to connect to (see listen)\n"
1271 " -t used with -N, forces use of tcp in live trace\n" 1299 " -t used with -N, forces use of tcp in live trace\n"
1300 " -b change kernel buffersize (in kilobytes per CPU)\n"
1272 "\n" 1301 "\n"
1273 " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n" 1302 " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n"
1274 " Uses same options as record, but does not run a command.\n" 1303 " Uses same options as record, but does not run a command.\n"
@@ -1281,9 +1310,10 @@ void usage(char **argv)
1281 " Stops the tracer from recording more data.\n" 1310 " Stops the tracer from recording more data.\n"
1282 " Used in conjunction with start\n" 1311 " Used in conjunction with start\n"
1283 "\n" 1312 "\n"
1284 " %s reset\n" 1313 " %s reset [-b size]\n"
1285 " Disables the tracer (may reset trace file)\n" 1314 " Disables the tracer (may reset trace file)\n"
1286 " Used in conjunction with start\n" 1315 " Used in conjunction with start\n"
1316 " -b change the kernel buffer size (in kilobytes per CPU)\n"
1287 "\n" 1317 "\n"
1288 " %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-E][-F filter][-v]\n" 1318 " %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-E][-F filter][-v]\n"
1289 " -i input file [default trace.dat]\n" 1319 " -i input file [default trace.dat]\n"
@@ -1364,7 +1394,7 @@ int main (int argc, char **argv)
1364 (strcmp(argv[1], "start") == 0) || 1394 (strcmp(argv[1], "start") == 0) ||
1365 ((extract = strcmp(argv[1], "extract") == 0))) { 1395 ((extract = strcmp(argv[1], "extract") == 0))) {
1366 1396
1367 while ((c = getopt(argc-1, argv+1, "+he:f:Fp:do:O:s:vg:l:n:P:N:t")) >= 0) { 1397 while ((c = getopt(argc-1, argv+1, "+he:f:Fp:do:O:s:vg:l:n:P:N:tb:")) >= 0) {
1368 switch (c) { 1398 switch (c) {
1369 case 'h': 1399 case 'h':
1370 usage(argv); 1400 usage(argv);
@@ -1467,6 +1497,9 @@ int main (int argc, char **argv)
1467 case 't': 1497 case 't':
1468 use_tcp = 1; 1498 use_tcp = 1;
1469 break; 1499 break;
1500 case 'b':
1501 buffer_size = atoi(optarg);
1502 break;
1470 } 1503 }
1471 } 1504 }
1472 1505
@@ -1475,7 +1508,18 @@ int main (int argc, char **argv)
1475 exit(0); 1508 exit(0);
1476 1509
1477 } else if (strcmp(argv[1], "reset") == 0) { 1510 } else if (strcmp(argv[1], "reset") == 0) {
1511 while ((c = getopt(argc-1, argv+1, "b:")) >= 0) {
1512 switch (c) {
1513 case 'b':
1514 buffer_size = atoi(optarg);
1515 /* Min buffer size is 1 */
1516 if (strcmp(optarg, "0") == 0)
1517 buffer_size = 1;
1518 break;
1519 }
1520 }
1478 disable_all(); 1521 disable_all();
1522 set_buffer_size();
1479 exit(0); 1523 exit(0);
1480 1524
1481 } else if (strcmp(argv[1], "list") == 0) { 1525 } else if (strcmp(argv[1], "list") == 0) {
@@ -1547,6 +1591,7 @@ int main (int argc, char **argv)
1547 1591
1548 if (events) 1592 if (events)
1549 enable_events(); 1593 enable_events();
1594 set_buffer_size();
1550 } 1595 }
1551 1596
1552 if (plugin) { 1597 if (plugin) {