latencytop.c revision de3d2ce46fc25c7b67ccbae4afe5f15e5357568f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2008-2009, Intel Corporation.
* All Rights Reserved.
*/
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <libgen.h>
#include <signal.h>
#include "latencytop.h"
/*
* Prints help for command line parameters.
*/
static void
print_usage(const char *execname)
{
" -h, --help\n"
" Print this help.\n"
" -t, --interval TIME\n"
" Set refresh interval to TIME. "
"Valid range [1...60] seconds, default = 5\n"
/*
* Keep this option private, until we have chance to properly document
* the format of translation rules.
*/
#if 0
" -c, --config FILE\n"
" Use translation rules defined in FILE.\n"
#endif
" -o, --output-log-file FILE\n"
" Output kernel log to FILE. Default = "
DEFAULT_KLOG_FILE "\n"
" -k, --kernel-log-level LEVEL\n"
" Set kernel log level to LEVEL.\n"
" 0(default) = None, 1 = Unmapped, 2 = Mapped, 3 = All.\n"
" -f, --feature [no]feature1,[no]feature2,...\n"
" [no]filter:\n"
" Filter large interruptible latencies, e.g. sleep.\n"
" [no]sched:\n"
" Monitors sched (PID=0).\n"
" [no]sobj:\n"
" Monitors synchronization objects.\n"
" [no]low:\n"
" Lower overhead by sampling small latencies.\n"
" -l, --log-period TIME\n"
" Write and restart log every TIME seconds, TIME > 60s\n");
}
/*
* Properly shut down when latencytop receives SIGINT or SIGTERM.
*/
/* ARGSUSED */
static void
signal_handler(int sig)
{
lt_gpipe_break("q");
}
/*
* Convert string to integer, return error if extra characters are found.
*/
static int
{
long ret;
return (-1);
}
return (-1);
}
return (0);
}
/*
* The main function.
*/
int
{
const char *opt_string = "t:o:k:hf:l:c:";
{
};
int optc;
int longind = 0;
int running = 1;
int unknown_option = FALSE;
int refresh_interval = 5;
int klog_level = 0;
int log_interval = 0;
long long last_logged = 0;
int retval = 0;
int gpipe;
int err;
/* Default global settings */
g_config.enable_filter = 0;
g_config.trace_sched = 0;
#ifdef EMBED_CONFIGS
#else
#endif
/* Parse command line arguments. */
switch (optc) {
case 'h':
print_usage(argv[0]);
goto end_none;
case 't':
"Invalid refresh interval: %s\n", optarg);
}
break;
case 'k':
lt_klog_set_log_level(klog_level) != 0) {
"Invalid log level: %s\n", optarg);
}
break;
case 'o':
if (err == 0) {
(void) printf("Writing to log file %s.\n",
optarg);
} else if (err == -1) {
"Log file name is too long: %s\n",
optarg);
} else if (err == -2) {
"Cannot write to log file: %s\n",
optarg);
}
break;
case 'f':
int v = TRUE;
v = FALSE;
}
g_config.enable_filter = v;
g_config.trace_sched = v;
g_config.trace_syncobj = v;
} else {
"Unknown feature: %s\n", token);
}
}
break;
case 'l':
log_interval < 60) {
"Invalid refresh interval: %s\n", optarg);
}
break;
case 'c':
"Configuration name is too long.\n");
} else {
}
break;
default:
break;
}
}
/* Throw error for commands like: "latencytop 12345678" */
(void) printf("Unknown option(s): ");
}
(void) printf("\n");
}
if (unknown_option) {
print_usage(argv[0]);
retval = 1;
goto end_none;
}
/* Initialization */
lt_klog_init();
if (lt_table_init() != 0) {
lt_display_error("Unable to load configuration table.\n");
retval = 1;
goto end_notable;
}
if (lt_dtrace_init() != 0) {
lt_display_error("Unable to initialize dtrace.\n");
retval = 1;
goto end_nodtrace;
}
(void) printf("Collecting data for %d seconds...\n",
gpipe = lt_gpipe_readfd();
for (;;) {
if (tsleep <= 0) {
break;
}
}
goto end_ubreak;
}
(void) lt_dtrace_work(0);
}
do {
(void) lt_dtrace_collect();
if (log_interval > 0 &&
}
} while (running != 0);
/* Cleanup */
}
return (retval);
}