📄 stat.c
字号:
/* 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 "modules.h"extern ptt_event_data_t ptt_event_array[];extern struct read_trace read_trace;extern struct int_list sorted_int_list;extern struct table_string_list table_string_list;/* store the number of occurences for each event */static int evt_tab[EVT_LAST] = {[0 ... (EVT_LAST-1)] = 0};static ptt_timestamp_t last_time; /* last timestamp */int init () { int ret; /* initialize the list of pid */ ret = sorted_int_list.init (); if (ret < 0) return ret; /* initialize the table of objects instances */ ret = table_string_list.init (NB_OBJ); if (ret < 0) return ret; return 0;}int handle (pid_t pid, ptt_timestamp_t time, ptt_event_t event) { char *list_name [PTT_MAXARG]; long long list_ll [PTT_MAXARG]; int list_int [PTT_MAXARG]; unsigned int list_uint [PTT_MAXARG]; int ret = 0; ret = sorted_int_list.insert (pid); /* counting pid */ if (ret < 0) return ret; if (time > last_time) last_time = time; /* keep last timestamp */ evt_tab[event]++; /* event count */ /* object count */ switch (event) { case EVT_START_USER_FUNC : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (THREAD, list_name[0]); break; case EVT_BARRIER_INIT : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (BARRIER, list_name[1]); break; case EVT_COND_INIT : /* in case of static init */ case EVT_COND_DESTROY_IN : case EVT_COND_BROAD_IN : case EVT_COND_SIGNAL_IN : case EVT_COND_WAIT_IN : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (CONDITION, list_name[1]); break; case EVT_MUTEX_INIT : /* in case of static init */ case EVT_MUTEX_DESTROY_IN : case EVT_MUTEX_LOCK_IN : case EVT_MUTEX_UNLOCK_IN : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (MUTEX, list_name[1]); break; case EVT_THREAD_INIT : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (THREAD, list_name[1]); break; case EVT_SEM_INIT : /* in case of static init */ case EVT_SEM_DESTROY_IN : case EVT_SEM_POST_IN : case EVT_SEM_WAIT_IN : case EVT_SEM_TRYWAIT_IN : case EVT_SEM_OPEN_IN : case EVT_SEM_CLOSE_IN : case EVT_SEM_UNLINK_IN : read_trace.info (list_name, list_int, list_uint, list_ll); table_string_list.insert (SEM, list_name[1]); break; default: break; } return ret;}void display () { int ind; int tot = 0; char *line = "***********************************************************" "**********\n"; /* display statistics */ printf ("%s", line); printf ("*** STATISTICS\n"); printf ("%s", line); printf ("*** LAST TIMESTAMP : %llu\n", last_time); printf ("%s", line); printf ("*** EVENT | NUMBER OF OCCURRENCES\n"); printf ("%s", line); for (ind = 1; ind < EVT_LAST-1; ind ++) { printf ("*** %-25s | %d\n", ptt_event_array[ind].name, evt_tab[ind]); tot += evt_tab[ind]; } printf ("%s", line); printf ("*** TOTAL OF EVENTS | %d\n", tot); printf ("%s", line); printf ("*** OBJECT | " "NUMBER OF INSTANCES ( LIST OF NAMES )\n"); printf ("%s", line); printf ("*** BARRIERS | "); table_string_list.display (BARRIER); printf ("*** CONDITIONAL VARIABLES | "); table_string_list.display (CONDITION); printf ("*** MUTEXES | "); table_string_list.display (MUTEX); printf ("*** SEMAPHORES | "); table_string_list.display (SEM); printf ("*** THREADS | "); table_string_list.display (THREAD); printf ("*** PROCESSES | "); sorted_int_list.display (THREAD); printf ("%s", line);}void close () { sorted_int_list.close (); table_string_list.close ();}struct stat stat = { .init = init, .handle = handle, .display = display, .close = close};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -