table.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 <stdlib.h>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <ctype.h>
#include "latencytop.h"
/*
* Structure that holds detail of a cause.
*/
typedef struct {
int cause_id;
int flags;
char *name;
} lt_cause_t;
/*
* Structure that represents a matched cause.
*/
typedef struct {
int priority;
int cause_id;
} lt_match_t;
/* All lt_cause_t that are created. */
static int causes_array_len = 0;
/*
* This hash table maps a symbol to a cause entry.
* key type is "char *" and value type is "lt_match_t *".
*/
/*
* This hash table maps a cause name to an cause id.
* Note only cause names that are found in D script is put in this table.
* key type is "char *" and value type is "int" (which is cause_id).
*/
/*
* Help function to free one lt_cause_t structure.
*/
/* ARGSUSED */
static void
{
}
/*
* Add a cause.
* Note this function takes ownership of char *name.
*/
static lt_cause_t *
{
return (entry);
}
/*
* Set a cause to "disabled" state.
*/
static void
{
}
}
/*
* Helper functions that reads a line from a char * array.
*/
static int
int *index)
{
return (0);
}
return (0);
}
--line_len;
++line;
break;
}
}
*line = 0;
return (1);
}
/*
* The main loop that parses the translation rules one line at a time,
* and construct latencytop lookup data structure from it.
*/
static int
{
char line[256];
int len;
int priority = 0;
char *match;
char *match_dup;
char *cause_str;
int current = 0;
¤t)) {
lt_display_error("Configuration line too long.\n");
goto err;
}
++begin;
}
if (*begin == '\0') {
/* empty line, ignore */
continue;
}
/* Delete trailing spaces. */
--end;
}
end[1] = 0;
if (*begin == '#') {
continue;
} else if (*begin == ';') {
char old_chr = 0;
/* special command */
/* ; disable_cause FSFlush Daemon */
/* ^ */
++begin;
++begin;
}
/* ; disable_cause FSFlush Daemon */
/* ^ */
if (*begin == '\0') {
continue;
}
++tmp) {
}
*tmp = 0;
if (old_chr == '\0') {
/* Must have an argument */
"Invalid command format: %s\n",
begin);
goto err;
}
++begin;
}
} else {
"Unknown command: %s\n", begin);
goto err;
}
continue;
}
/* 10 genunix`indir Syscall indir */
/* ^ */
"Invalid configuration line: %s\n", line);
goto err;
}
/* 10 genunix`indir Syscall indir */
/* ^ */
++begin;
}
if (*begin == 0) {
"Invalid configuration line: %s\n", line);
goto err;
}
/* 10 genunix`indir Syscall indir */
/* -----^ */
++tmp) {
}
if (*tmp == '\0') {
"Invalid configuration line: %s\n", line);
goto err;
}
*tmp = 0;
/* Check if we have mapped this function before. */
match_entry = (lt_match_t *)
if (match_entry != NULL &&
/* We already have a higher entry. Ignore this. */
continue;
}
/* 10 genunix`indir Syscall indir */
/* -------------------------------------^ */
++begin;
}
if (*begin == 0) {
"Invalid configuration line: %s\n", line);
goto err;
}
/* Check if we have mapped this cause before. */
cause = (lt_cause_t *)
}
}
return (0);
err:
return (-1);
}
/*
* Init function, called when latencytop starts.
* It loads the translation rules from a file.
* A configuration file defines some causes and symbols matching these causes.
*/
int
lt_table_init(void)
{
char *config_loaded = NULL;
int config_loaded_len = 0;
int work_len = 0;
#ifdef EMBED_CONFIGS
work = (char *)latencytop_trans;
#endif
"Unable to open configuration file.\n");
return (-1);
}
"Unable to read configuration file.\n");
return (-1);
}
(void) printf("Loaded configuration from %s\n",
}
/* 0 is not used, to keep a place for bugs etc. */
return (-1);
}
if (config_loaded != NULL) {
}
return (0);
}
/*
* Some causes, such as "lock spinning", does not have stack trace.
* Instead, their names are explicitly specified in DTrace script.
* This function will resolve such causes, and dynamically add them
* to the global tables when first met (lazy initialization).
* auto_create: set to TRUE will create the entry if it is not found.
* Returns cause_id of the cause.
*/
int
{
int cause_id = INVALID_CAUSE;
if (named_causes == NULL) {
} else {
named_causes, name));
}
int flags = CAUSE_FLAG_SPECIAL;
if (name[0] == '#') {
}
return (INVALID_CAUSE);
}
}
return (cause_id);
}
/*
* Try to map a symbol on stack to a known cause.
* module_func has the format "module_name`function_name".
* cause_id and priority will be set if a cause is found.
* Returns 1 if found, 0 if not found.
*/
int
{
if (symbol_lookup_table == NULL) {
return (0);
}
match = (lt_match_t *)
match = (lt_match_t *)
}
}
return (0);
} else {
return (1);
}
}
/*
* Get the display name of a cause. Cause_id must be valid,
* which is usually return from lt_table_lookup_cause() or
* lt_table_lookup_named_cause().
*/
const char *
{
return (NULL);
}
return (NULL);
} else {
}
}
/*
* Check a cause's flag, e.g. if it has CAUSE_FLAG_DISABLED.
* Use CAUSE_ALL_FLAGS to get all flags at once.
*/
int
{
return (0);
}
return (0);
} else {
}
}
/*
* Clean up function.
* Free the resource used for symbol table. E.g. symbols, causes.
*/
void
lt_table_deinit(void)
{
if (symbol_lookup_table != NULL) {
}
if (named_causes != NULL) {
named_causes = NULL;
}
if (causes_array != NULL) {
causes_array = NULL;
}
causes_array_len = 0;
}