util.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 <libintl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <procfs.h>
#include <fcntl.h>
#include "latencytop.h"
/* pipe that breaks the event loop (and exit early) */
static int signal_pipe[2];
/*
* Get current system time in milliseconds (1e-3).
*/
lt_millisecond(void)
{
struct timeval p;
(void) gettimeofday(&p, NULL);
}
/*
* Wrapper of gettext().
*/
const char *
{
return ("");
}
}
/*
* Checks if OOM happens by comparing pointers with NULL in various places.
*/
void
lt_check_null(void *p)
{
if (p == NULL) {
(void) printf("Out of memory!\n");
g_assert(0);
exit(2);
}
}
/*
* Safe malloc.
*/
void *
{
return (ret);
}
/*
* Safe alloc with memory cleared.
* Named it "zalloc" because its signature is different from
* calloc() in stdlib.
*/
void *
{
return (ret);
}
/*
* Safe strdup.
*/
char *
{
return (ret);
}
/*
* Get string for current time, e.g. YYYY-MM-DD
*/
void
{
time_t t;
int i;
(void) time(&t);
buffer[i] = 0;
} else {
break;
}
}
}
/*
* Retrieves process exeutable name etc. from /proc.
*/
char *
{
int fd;
int ret;
if (fd == -1) {
return (NULL);
}
if (ret < 0) {
return (NULL);
}
switch (field) {
case LT_FIELD_FNAME:
case LT_FIELD_PSARGS:
}
return (NULL);
}
/*
* Help function to update the data structure.
*/
void
{
switch (type) {
case LT_STAT_COUNT:
break;
case LT_STAT_SUM:
break;
case LT_STAT_MAX:
}
break;
default:
break;
}
}
/*
* Help function to sort by total.
*/
int
{
/*
* ->data.total is int64, so we can't simply return
*/
return (1);
return (-1);
} else {
return (0);
}
}
/*
* Help function to sort by max.
*/
int
{
return (1);
return (-1);
} else {
return (0);
}
}
/*
* Help function to sort by count.
*/
int
{
return (1);
return (-1);
} else {
return (0);
}
}
/*
* Help function to sort by average.
*/
int
{
return (1);
return (-1);
} else {
return (0);
}
}
/*
* Create pipe for signal handler and wakeup.
*/
void
lt_gpipe_init(void)
{
(void) pipe(signal_pipe);
}
/*
* Release pipe used in signal handler.
*/
void
lt_gpipe_deinit(void)
{
(void) close(signal_pipe[0]);
}
/*
* Break from main loop early.
*/
void
lt_gpipe_break(const char *ch)
{
}
/*
* Returns fd# used to detect "break main loop".
*/
int
lt_gpipe_readfd(void)
{
return (signal_pipe[0]);
}
/*
* Check if a file exists.
*/
int
lt_file_exist(const char *name)
{
return (1);
} else {
return (0);
}
}