|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "BufferLogger.hpp" 00023 00024 #include <stdlib.h> 00025 #include "../Timer.hpp" 00026 #include "../../libmasa/libmasa.hpp" 00027 00028 BufferLogger::BufferLogger(string file) 00029 { 00030 prev_stats.time = 0; 00031 prev_stats.bufferUsage = 0; 00032 prev_stats.blockingReadTime = 0; 00033 prev_stats.blockingWriteTime = 0; 00034 prev_stats.totalReadBytes = 0; 00035 prev_stats.totalWriteBytes = 0; 00036 00037 this->file = fopen(file.c_str(), "wt"); 00038 if (this->file == NULL) { 00039 fprintf(stderr, "Could not create buffer statistics file.\n"); 00040 exit(1); 00041 } 00042 } 00043 00044 BufferLogger::~BufferLogger() 00045 { 00046 if (this->file != NULL) { 00047 fclose(this->file); 00048 } 00049 } 00050 00051 void BufferLogger::logHeader(int bufferMax) { 00052 fprintf(file, "#buffer_max=%d\n", bufferMax/sizeof(cell_t)); 00053 fflush(file); 00054 } 00055 00056 void BufferLogger::logBuffer(buffer2_statistics_t &curr_stats) { 00057 buffer2_statistics_t delta_stats = curr_stats - prev_stats; 00058 prev_stats = curr_stats; 00059 00060 float delta = 0; 00061 float psi_in = 0; 00062 float psi_out = 0; 00063 00064 int size = sizeof(cell_t); 00065 if (delta_stats.time >= 0.001) { 00066 delta = ((float)delta_stats.bufferUsage/size)/delta_stats.time; 00067 } 00068 if (abs(delta_stats.time - delta_stats.blockingReadTime) > 0.000001) { 00069 psi_in = ((float)delta_stats.totalReadBytes/size)/delta_stats.time*delta_stats.blockingReadTime/(delta_stats.time-delta_stats.blockingReadTime); 00070 } 00071 if (abs(delta_stats.time - delta_stats.blockingWriteTime) > 0.000001) { 00072 psi_out = ((float)delta_stats.totalWriteBytes/size)/delta_stats.time*delta_stats.blockingWriteTime/(delta_stats.time-delta_stats.blockingWriteTime); 00073 } 00074 00075 fprintf(file, "%.2f\t%d\t%d\t%d\t%.2f\t%.2f\t%.2f\t%d\t%d\t%d\t%.2f\t%.2f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", 00076 curr_stats.time, // 1 00077 curr_stats.bufferUsage/size, // 2 00078 curr_stats.totalReadBytes/size, curr_stats.totalWriteBytes/size, // 3 4 00079 curr_stats.blockingReadTime, curr_stats.blockingWriteTime, // 5 6 00080 delta_stats.time, // 7 00081 delta_stats.bufferUsage/size, // 8 00082 delta_stats.totalReadBytes/size, delta_stats.totalWriteBytes/size, // 9 10 00083 delta_stats.blockingReadTime, delta_stats.blockingWriteTime, // 11 12 00084 delta, psi_in, psi_out, // 13 14 15 00085 (delta_stats.totalReadBytes/size)/delta_stats.time, // 16 00086 (delta_stats.totalWriteBytes/size)/delta_stats.time, // 17 00087 delta+psi_in, delta+psi_out); // 18 19 00088 00089 fflush(file); 00090 } 00091 00092
1.7.6.1