📄 amdb_analysis.cc
字号:
// amdb_analysis.cc -*- c++ -*-// Copyright (c) 1998, Regents of the University of California// $Id: amdb_analysis.cc,v 1.7 2000/03/15 00:24:18 mashah Exp $#ifdef __GNUG__#pragma implementation "amdb_analysis.h"#endif// VCPORT_B#ifdef HAVE_VALUES_H#include <values.h>#endif// VCPORT_E// VCPORT_B#if (defined WIN32) || (__GNUG__==3)// Disable debug warnings for classes that get too long because of templates.#pragma warning(disable: 4786)#include <fstream>#include <iostream>#include <strstream>#include <vector>#include <algorithm>using namespace std;#else#include <fstream.h>#include <iostream.h>#include <strstream.h>// STL#include <vector.h>#include <algo.h>#endif// VCPORT_E#include <stdlib.h>#include <stdio.h>#include <math.h>#include "amdb_analysis.h"#include "amdb_clustering.h"//#include <netinet/in.h> this doesn't work//#include <arpa/inet.h> this doesn't work either#include <assert.h>#include "gist.h"#include "gist_compat.h"#include "gist_p.h"#include "amdb_ext.h"#include "amdb_wkldprofile.h"#include "amdb_wkldstats.h"#include "amdb_splitstats.h"#include "amdb_penaltystats.h"#include "amdb_treemap.h"#include "gist_query.h"const int amdb_analysis::_MAXLINE = 8192;///////////////////////////////////////////////////////////////////////////////// amdb_analysis::init - initialize after generating profile//// Description:// - initialize analysis with tree and profile, compute treemap// for tree// - call profile->computeTotals()// - read queryFile and store qualification and limit in profile.queries[]///////////////////////////////////////////////////////////////////////////////rc_tamdb_analysis::init( const char* filename, // in: of tree amdb_wkldprofile* prof, // in: of tree/queryFile const char* queryFile, // in: name of script file int numRandomRuns, // in float targetUtil) // in{ parameters.randomRuns = numRandomRuns; parameters.targetUtil = targetUtil; actualAnalysis.tree = new gist(); rc_t status = actualAnalysis.tree->open(filename); if (status != RCOK) { return(status); } actualAnalysis.filename = new char[strlen(filename)+1]; (void) memcpy(actualAnalysis.filename, filename, strlen(filename)+1); actualAnalysis.profile = prof; actualAnalysis.map = new amdb_treemap(); actualAnalysis.tree->computeTreeMap(actualAnalysis.map); this->queryFile = new char[strlen(queryFile)+1]; (void) memcpy(this->queryFile, queryFile, strlen(queryFile)+1); actualAnalysis.profile->computeTotals(); // scan scriptfile ifstream s(queryFile); if (s.fail()) { return(eFILEERROR); } char buf[1024]; int i = 0; while (s.getline(buf, sizeof(buf))) { // XXX we should be parsing regular scripts prof->setQual(i, buf, 0); i++; } s.close(); return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_analysis::~amdb_analysis - Destructor//// Description:// - free all state/////////////////////////////////////////////////////////////////////////amdb_analysis::~amdb_analysis(){ clear();}/////////////////////////////////////////////////////////////////////////// amdb_analysis::TreeAnalysis::clear - free state//// Description:// - only free 'tree' if explicitly requestd (not requested// for actual tree)/////////////////////////////////////////////////////////////////////////voidamdb_analysis::TreeAnalysis::clear(){ if (tree != NULL) { delete tree; tree = NULL; } if (filename != NULL) { delete [] filename; filename = NULL; } if (map != NULL) { delete map; map = NULL; } if (profile != NULL) { delete profile; profile = NULL; } if (wkldStats != NULL) { delete wkldStats; wkldStats = NULL; } if (splitStats != NULL) { delete splitStats; splitStats = NULL; } if (penaltyStats != NULL) { delete penaltyStats; penaltyStats = NULL; }}/////////////////////////////////////////////////////////////////////////// amdb_analysis::clear - Free state//// Description://///////////////////////////////////////////////////////////////////////voidamdb_analysis::clear(){ actualAnalysis.clear(); optAnalysis.clear(); if (optClustering != NULL) { delete optClustering; optClustering = NULL; } delete [] queryFile; if (_queries != NULL) { Vector::const_iterator it; for (it = _queries->begin(); it != _queries->end(); it++) { gist_query_t* query = (gist_query_t *) *it; delete query; } delete _queries; _queries = NULL; }}/////////////////////////////////////////////////////////////////////////// amdb_analysis::read - Read analysis in binary//// Description://// Return Values:// RCOK/////////////////////////////////////////////////////////////////////////rc_tamdb_analysis::read( const char* filename) // in: input filename{ // VCPORT_B#ifdef WIN32 ifstream s(filename, ios_base::in | ios_base::binary);#else ifstream s(filename);#endif // VCPORT_E if (!s.good()) { return eFILEERROR; } clear(); // read parameters, actualAnalysis and optAnalysis W_DO(parameters.read(s)); W_DO(actualAnalysis.read(s)); W_DO(optAnalysis.read(s)); // read optClustering (indicator stored in network order) int hasOptClustering; s.read((char *) &hasOptClustering, sizeof(hasOptClustering)); hasOptClustering = ntohl(hasOptClustering); if (hasOptClustering) { optClustering = new amdb_clustering::Clustering(); W_DO(optClustering->read(s)); } // read queryFile (length stored in network order) int len; s.read((char *) &len, sizeof(len)); len = ntohl(len); if (len > 0) { queryFile = new char[len+1]; (void) memset(queryFile, 0, len+1); s.read(queryFile, len); } else { queryFile = NULL; } // check for errors if (!s) { return(eFILEERROR); } s.close(); return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_analysis::write - Write analysis to file//// Description://// Return Values:// RCOK// eFILEERROR/////////////////////////////////////////////////////////////////////////rc_tamdb_analysis::write( const char* filename, // in: output filename bool ascii) // in: if true, write out in ASCII{ // VCPORT_B#ifdef WIN32 ofstream s(filename, ios_base::out | ios_base::binary);#else ofstream s(filename);#endif // VCPORT_E if (!s.good()) { return eFILEERROR; } // write parameters, actualAnalysis and optAnalysis W_DO(parameters.write(s, ascii)); W_DO(actualAnalysis.write(s, ascii)); W_DO(optAnalysis.write(s, ascii)); if (!ascii) { // write indicator (in network order) and optClustering int hasOptClustering = htonl(optClustering != NULL); s.write((char *) &hasOptClustering, sizeof(hasOptClustering)); if (optClustering != NULL) { W_DO(optClustering->write(s, ascii)); } // write queryFile (its size in network order) int len = htonl(strlen(queryFile)); s.write((char *) &len, sizeof(len)); s.write(queryFile, strlen(queryFile)); // don't use len here! } else { int hasOptClustering = htonl(optClustering != NULL); s << hasOptClustering << "\n"; if (optClustering != NULL) { W_DO(optClustering->write(s, ascii)); } s << queryFile << "\n"; } return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_analysis::TreeAnalysis::read - read TreeAnalysis in binary//// Description:// - doesn't open tree//// Return Values:// RCOK// eFILEERROR/////////////////////////////////////////////////////////////////////////rc_tamdb_analysis::TreeAnalysis::read( istream& s){ // read filename (length stored in network order) int len; s.read((char *) &len, sizeof(len)); len = ntohl(len); if (len > 0) { filename = new char[len+1]; (void) memset(filename, 0, len+1); s.read(filename, len); } else { filename = NULL; } tree = NULL;#if 0 // open tree if (filename != NULL) { tree = new gist(); rc_t status; if ((status = tree->open(filename)) != RCOK) { return(status); } }#endif // read map, profile, wkldStats, splitStats and penaltyStats, // together with indicators int notNull; s.read((char *) ¬Null, sizeof(notNull)); notNull = ntohl(notNull); if (notNull) { map = new amdb_treemap(); W_DO(map->read(s)); } else { map = NULL; } s.read((char *) ¬Null, sizeof(notNull)); notNull = ntohl(notNull); if (notNull) { profile = new amdb_wkldprofile(); W_DO(profile->read(s)); if (map != NULL) { // might be needed for further analyses profile->setTreeMap(map); } } else { profile = NULL; } s.read((char *) ¬Null, sizeof(notNull)); notNull = ntohl(notNull); if (notNull) { wkldStats = new amdb_wkldstats(); W_DO(wkldStats->read(s)); } else { wkldStats = NULL; } s.read((char *) ¬Null, sizeof(notNull)); notNull = ntohl(notNull); if (notNull) { splitStats = new amdb_splitstats(); W_DO(splitStats->read(s)); } else { splitStats = NULL; } s.read((char *) ¬Null, sizeof(notNull)); notNull = ntohl(notNull); if (notNull) { penaltyStats = new amdb_penaltystats(); W_DO(penaltyStats->read(s)); } else { penaltyStats = NULL; } return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_analysis::TreeAnalysis::write - write TreeAnalysis in binary//// Description:// - doesn't save tree, assumed to be done independently//// Return Values:// RCOK// eFILEERROR/////////////////////////////////////////////////////////////////////////rc_tamdb_analysis::TreeAnalysis::write( ostream& s, bool ascii)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -