00001 /* 00002 * SwapMonitor.h : part of the Mace toolkit for building distributed systems 00003 * 00004 * Copyright (c) 2007, Charles Killian, Dejan Kostic, Ryan Braud, James W. Anderson, John Fisher-Ogden, Calvin Hubble, Duy Nguyen, Justin Burke, David Oppenheimer, Amin Vahdat, Adolfo Rodriguez, Sooraj Bhat 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the names of Duke University nor The University of 00017 * California, San Diego, nor the names of the authors or contributors 00018 * may be used to endorse or promote products derived from 00019 * this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00030 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 * ----END-OF-LEGAL-STUFF---- */ 00033 00034 /* Reports periodic system (virtual memory) swap statistics: cumulative pages 00035 * swapped in/out and pages swapped in/out for a user-defineable time period. 00036 * Only known to work with Linux v2.6. */ 00037 00038 #ifndef __SWAP_MONITOR_H 00039 #define __SWAP_MONITOR_H 00040 00041 #include <fstream> 00042 #include "Scheduler.h" 00043 00055 00056 class SwapMonitor : public TimerHandler 00057 { 00058 public: 00059 SwapMonitor(); 00060 void expire(); 00061 static void runSwapMonitor(); 00062 static void stopSwapMonitor(); 00063 00064 static const uint64_t DEFAULT_FREQUENCY = 5*1000*1000; 00065 00066 private: 00067 void fillLast(); 00068 00069 static SwapMonitor* instance; 00070 bool halt; 00071 uint64_t frequency; /* microseconds */ 00072 std::ifstream vmstat_file; 00073 uint32_t cumulative_in; 00074 uint32_t cumulative_out; 00075 uint32_t last_in; 00076 uint32_t last_out; 00077 double peak_in; 00078 double peak_out; 00079 }; 00080 00083 #endif