Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

perf-event.c

Go to the documentation of this file.
00001 /*
00002 **  $Id$
00003 **
00004 **  perf-event.c
00005 **
00006 **  Copyright (C) 2002 Sourcefire,Inc
00007 **  Marc Norton <mnorton@sourcefire.com>
00008 **  Dan Roelker <droelker@sourcefire.com>
00009 **
00010 **  NOTES
00011 **  5.28.02 - Initial Source Code. Norton/Roelker
00012 **
00013 **
00014 **  This program is free software; you can redistribute it and/or modify
00015 **  it under the terms of the GNU General Public License as published by
00016 **  the Free Software Foundation; either version 2 of the License, or
00017 **  (at your option) any later version.
00018 **
00019 **  This program is distributed in the hope that it will be useful,
00020 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 **  GNU General Public License for more details.
00023 **
00024 **  You should have received a copy of the GNU General Public License
00025 **  along with this program; if not, write to the Free Software
00026 **  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00027 **
00028 */
00029 
00030 #include "snort.h"
00031 #include "util.h"
00032 
00033 int DisplayEventPerfStats(SFEVENT_STATS *sfEventStats);
00034 
00035 SFEVENT *GetEventPtr() { return &sfPerf.sfEvent; }
00036 
00037 int InitEventStats(SFEVENT *sfEvent)
00038 {
00039     sfEvent->NQEvents = 0;
00040     sfEvent->QEvents  = 0;
00041 
00042     return 0;
00043 }
00044 
00045 int UpdateNQEvents()
00046 {
00047     SFEVENT *sfEvent = GetEventPtr();
00048 
00049     if(!(sfPerf.iPerfFlags & SFPERF_EVENT))
00050     {
00051         return 0;
00052     }
00053 
00054     sfEvent->NQEvents++;
00055     sfEvent->TotalEvents++;
00056 
00057     return 0;
00058 }
00059 
00060 int UpdateQEvents()
00061 {
00062     SFEVENT *sfEvent = GetEventPtr();
00063 
00064     if(!(sfPerf.iPerfFlags & SFPERF_EVENT))
00065     {
00066         return 0;
00067     }
00068 
00069     sfEvent->QEvents++;
00070     sfEvent->TotalEvents++;
00071 
00072     return 0;
00073 }
00074 
00075 int ProcessEventStats(SFEVENT *sfEvent)
00076 {
00077     SFEVENT_STATS sfEventStats;
00078 
00079     sfEventStats.NQEvents = sfEvent->NQEvents;
00080     sfEventStats.QEvents = sfEvent->QEvents;
00081     sfEventStats.TotalEvents = sfEvent->TotalEvents;
00082 
00083     if(sfEvent->TotalEvents)
00084     {
00085         sfEventStats.NQPercent = 100.0 * (double)sfEvent->NQEvents / 
00086                                  (double)sfEvent->TotalEvents;
00087         sfEventStats.QPercent  = 100.0 * (double)sfEvent->QEvents / 
00088                                  (double)sfEvent->TotalEvents;
00089     }
00090     else
00091     {
00092         sfEventStats.NQPercent = 0;
00093         sfEventStats.QPercent = 0;
00094     }
00095 
00096     sfEvent->NQEvents    = 0;
00097     sfEvent->QEvents     = 0;
00098     sfEvent->TotalEvents = 0;
00099 
00100     DisplayEventPerfStats(&sfEventStats);
00101 
00102     return 0;
00103 }
00104 
00105 int DisplayEventPerfStats(SFEVENT_STATS *sfEventStats)
00106 {
00107     LogMessage("\n\nSnort Setwise Event Stats\n");
00108     LogMessage(    "-------------------------\n");
00109 
00110     LogMessage( "Total Events:           %llu\n", sfEventStats->TotalEvents);
00111     LogMessage( "Qualified Events:       %llu\n", sfEventStats->QEvents);
00112     LogMessage( "Non-Qualified Events:   %llu\n", sfEventStats->NQEvents);
00113 
00114     LogMessage("%%Qualified Events:      %.4f%%\n", sfEventStats->QPercent);
00115     LogMessage("%%Non-Qualified Events:  %.4f%%\n", sfEventStats->NQPercent);
00116 
00117     return 0;
00118 }
00119     
00120 

Generated on Sun May 14 14:51:15 2006 by  doxygen 1.4.2