ptt_stat.c

来自「linux下的多线程调试工具」· C语言 代码 · 共 83 行

C
83
字号
/* Copyright (C) 2004,2005,2006  Bull S.A. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#if HAVE_CONFIG_H#include <config.h>#endif#include <stdlib.h>#include <unistd.h>#include "types.h"#include "modules.h"extern struct give_name give_name;extern struct interval interval;extern struct read_trace read_trace;extern struct stat stat;static void usage () {    fprintf (stderr, "Usage : ptt-stat [option] file\n");    fprintf (stderr, "-a alias_file : use alias to describe objects\n");    fprintf (stderr, "-h : this small usage guide\n");}/* compute and display statistics on the binary file */int main (int argc, char *argv[]) {    ptt_header_t head;    int option;    extern char *optarg;    extern int optind, optopt;    const char * optstring = "+ha:";    ptt_event_t event;    ptt_timestamp_t time;    pid_t pid;    int ret;    char *alias_file = NULL;    while ((option = getopt (argc, argv, optstring)) != -1) {        switch (option) {            case 'a': alias_file = optarg; continue;            case '?':                fprintf (stderr, "Unrecognized option: -%c\n", optopt);            case 'h': usage(); return 1;	}    }    if (argc - optind < 1) { usage(); return 1; }    /* init read submodule */    ret = give_name.init(alias_file);    if (ret < 0) return -ret;    ret =interval.init(INT_NULL,0,0);    if (ret < 0) return -ret;    /* Read the header */    ret = read_trace.init(argv[optind], &head);    if (ret < 0) return -ret;	    /* Initialize the statistics */    ret = stat.init();    if (ret < 0) return -ret;	    while (read_trace.read_fast (&pid, &time, &event) > 0) {        ret = stat.handle(pid, time, event);	if (ret < 0) return -ret;    }    stat.display();    stat.close();    read_trace.close();    return -ret;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?