00001 // Copyright (C) 2004, Kenneth C. Schalk 00002 // 00003 // This file is part of Vesta. 00004 // 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // Vesta is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 // nfsStats.H - declaration of a class which gathers NFS call 00020 // statistics 00021 00022 // Last modified on Mon May 23 21:52:13 EDT 2005 by ken@xorian.net 00023 00024 #ifndef NFSSTATS_H 00025 #define NFSSTATS_H 00026 00027 #include <sys/time.h> 00028 00029 #include <Basics.H> 00030 00031 // An instance of this class gets created for each NFS server thread. 00032 // It records the number of NFS calls and total time spent servicing 00033 // all calls over the lifetime of the thread. 00034 class NFS_Call_Stats 00035 { 00036 private: 00037 // Single linked list of all instances of this class. 00038 static Basics::mutex head_mu; 00039 static NFS_Call_Stats *head; 00040 NFS_Call_Stats *next; 00041 00042 // Protext local fields. 00043 Basics::mutex mu; 00044 00045 // Statistics for one NFS-servicing thread. 00046 Basics::uint64 call_count; 00047 Basics::uint64 elapsed_secs; 00048 Basics::uint32 elapsed_usecs; 00049 00050 // Add the statistics from this instance into a running total. 00051 void accumulateStats(/*OUT*/ Basics::uint64 &calls, 00052 /*OUT*/ Basics::uint64 &secs, 00053 /*OUT*/ Basics::uint32 &usecs); 00054 00055 // Record an NFS call. 00056 void recordCall(Basics::uint32 secs, Basics::uint32 &usecs); 00057 00058 public: 00059 00060 NFS_Call_Stats(); 00061 ~NFS_Call_Stats(); 00062 00063 static void getStats(/*OUT*/ Basics::uint64 &calls, 00064 /*OUT*/ Basics::uint64 &secs, 00065 /*OUT*/ Basics::uint32 &usecs); 00066 00067 // Class whose creation and destruction mark the beginning and end 00068 // of a call. 00069 class Helper 00070 { 00071 private: 00072 struct timeval call_start; 00073 00074 NFS_Call_Stats &stats; 00075 public: 00076 Helper(NFS_Call_Stats &my_stats); 00077 ~Helper(); 00078 }; 00079 00080 friend class Helper; 00081 }; 00082 00083 #endif // NFSSTATS_H