Exemple #1
0
/** Create a directory
 * Open and write some content in a file inside the directory
 * If directory exists delete it altogether.
 */
void setupDirContents()
{
  CFileOutputStream f;

  string dir_name = "dir_a";
  string file_name = "file_b";
  CPose2D a_pose(1, 2, DEG2RAD(40));

  if (!directoryExists(dir_name)) {
    cout << "Creating directory... " << endl;
    createDirectory(dir_name);
    f.open(dir_name + "/" + file_name);
    if (f.fileOpenCorrectly()) { // checking for errors...
      cout << "file was opened correctly" << endl;
      // CSerializable form (binary)
      f.printf("some random text ...\n");
      f.printf("some more random text.\n");
      f.printf("CPose2D: %s", a_pose.asString().c_str());
      f.close();
    }
    else {
      cout << "file was NOT opened successfully" << endl;
      return;
    }
  }
  else {
    cout << "directory " << dir_name << " exists. " << endl;
    cout << "removing directory altogether... " << endl;
    deleteFilesInDirectory(dir_name, 
        /* deleteDirectoryAsWell = */ true);
  }
}
Exemple #2
0
/** Initialize a directory along with some dummy content.
 * Rename the directory and filenames inside it to
 * ${PREVIOUS_FNAME}_renamed_datetime
 */
void renameDirContents()
{
	string dir_name = "dir_b";
	CFileOutputStream f;
	string fname = "file";
	stringstream ss_tmp;

	// get the current datetime as a string - add it to the renamed fnames
	TTimeStamp cur_time(getCurrentTime());
	string cur_time_str = dateTimeToString(cur_time);
	string cur_time_validstr(fileNameStripInvalidChars(cur_time_str));
	string string_to_add = "_renamed_" + cur_time_validstr;

	bool success;  // flag for specifying whether an operation was successfully
	// completed

	if (!directoryExists(dir_name))
	{
		cout << "directory " << dir_name << " doesn't exist. " << endl;
		cout << "Creating it.. " << endl;
		success = createDirectory(dir_name);
		if (!success)
		{
			THROW_EXCEPTION(
				"There was an error creating the directory: " + dir_name);
		}
	}

	// build the initial directory contents
	for (int i = 0; i < 10; i++)
	{
		ss_tmp.str("");
		ss_tmp << dir_name << "/" << fname << i;
		f.open(ss_tmp.str());
		f.printf("dummy text in file...");
		f.close();
	}

	// rename all the contents (of depth 1)
	for (int i = 0; i < 10; i++)
	{
		ss_tmp.str("");
		ss_tmp << dir_name << "/" << fname << i;
		success = renameFile(
			ss_tmp.str(),
			/*new_name = */ ss_tmp.str() + string_to_add);
	}

	// finally rename the directory itself
	cout << "Renaming directory " << dir_name << " to: " << dir_name
		 << string_to_add << endl;
	string* err_msg = nullptr;  // flag for catching the error msg if any..
	success = renameFile(dir_name, dir_name + string_to_add, err_msg);
	if (success)
	{
		cout << "Directory renaming was successful!" << endl;
	}
	else
	{
		THROW_EXCEPTION("Error while trying to rename directory: " + dir_name);
	}
}
Exemple #3
0
// アイテムのサイズを返す
long long enum_and_print(CFileOutputStream& out, wchar_t* szDir, int nIndent)
{
	//CPUをあんまり食いつぶさないように。
	::Sleep(1);

	//ワイルドカード式ファイルパスを構築
	wchar_t* szPath = szDir;
	wcscat_s(szPath, XP_MAX_PATH, L"\\*");

	//ファイルタイトル部分を覚えておく
	wchar_t* pTitle = wcschr(szPath, L'\0') - 1;
	int nTitleMax = XP_MAX_PATH - (int)(pTitle - szPath);

	//ファイル一覧収集
	WIN32_FIND_DATA fd;
	HANDLE hFind = ::FindFirstFile(szPath, &fd);
	std::list<WIN32_FIND_DATA> files;
	if(hFind!=INVALID_HANDLE_VALUE){
		do{
			//「.」と「..」はスキップ
			if(wcscmp(fd.cFileName, L".")==0)continue;
			if(wcscmp(fd.cFileName, L"..")==0)continue;

			//リスト構築
			files.push_back(fd);
		}
		while(::FindNextFile(hFind, &fd));
	}
	::FindClose(hFind);

	//ファイル一覧ソート
	files.sort();

	//ファイル一覧処理
	long long totalsize = 0;
	std::list<WIN32_FIND_DATA>::const_iterator p = files.begin(), q = files.end();
	for(; p != q; p++){
		//インデント出力
		for(int i=0;i<nIndent;i++)out.Write(L"\t");

		// ファイル名出力
		const wchar_t* test = p->cFileName;
		const WIN32_FIND_DATA* test2 = &(*p);
		
		out.Write(p->cFileName);

		// タブ区切りで属性値を出力
		out.Write(L"\t");
		long long size = p->nFileSizeLow | (((long long)p->nFileSizeHigh) << 32);
		out.WriteF(L"Size:%lld", size);
		//out.Seek();

		//ディレクトリを再帰巡回
		if(p->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
			if(p->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT){
				// シンボリックリンクまたはジャンクションなので配下は無視
				out.Write(L",Type:ReparsePoint\n");
			}
			else{
				// フォルダ情報出力スペース予約
				out.WriteF(L",Type:Folder,FolderSize:xxxxxxxxxxxxxxxxxxxx", size);
				long long foldersizepos = out.Tell() - 20 * 2;
				out.Write(L"\n");
				// 配下情報
				wcscpy_s(pTitle, nTitleMax, p->cFileName);
				size += enum_and_print(out, szPath, nIndent+1);
				size += 10;
				// 保存すべきサイズをひとまず保持(2stage目でこの値は吐き出す)
				g_sizes[foldersizepos] = size;
			}
		}
		else{
			out.Write(L",Type:File\n");
		}

		// サイズ加算
		totalsize += size;
	}
	return totalsize;
}
// ------------------------------------------------------
//                     run_build_tables
// ------------------------------------------------------
int run_build_tables(const std::string &PERF_DATA_DIR)
{
	using namespace std;
	using namespace mrpt;
	using namespace mrpt::system;
	using namespace mrpt::utils;


	// Perf. results are in:
	//  PERF_DATA_DIR + mrpt::format("/perf-results-%i.%i.%i%s-%s-%ibit.dat"
	// Data is serializations of: vector<pair<string,double> >  all_perf_data; // pair: description, time
	CDirectoryExplorer::TFileInfoList  fils;
	CDirectoryExplorer::explore(PERF_DATA_DIR,FILE_ATTRIB_ARCHIVE,fils);
	CDirectoryExplorer::filterByExtension(fils,"dat");

	// make list of "perf-results-<SUFIX>" -> "whole path file"
	vector<TPerfField>  lstConfigurations;

	for (size_t i=0;i<fils.size();i++)
	{
		if (!strStarts(fils[i].name,"perf-results")) continue;
		size_t p = fils[i].name.find(".dat");
		if (p==string::npos) continue;

		const string config_name = fils[i].name.substr(13,p-13);

		TPerfField dat;
		dat.config_name = config_name;
		dat.file_path   = fils[i].wholePath;

		CFileInputStream  f(dat.file_path);
		f >> dat.all_perf_data;
		lstConfigurations.push_back(dat);

		cout << " Read: " << setw(30) << config_name << " with " << dat.all_perf_data.size() << " entries.\n";
	}

	std::sort(lstConfigurations.begin(),lstConfigurations.end(), func_comp_entries);

	ASSERT_( directoryExists(PERF_DATA_DIR+string("/perf-html/") ) )

	CFileOutputStream  fo;
	// ====================================================
	//                  index.html
	// ====================================================
	const string out_fil_index = PERF_DATA_DIR+string("/perf-html/" "index.html");
	cout << "Generating: " << out_fil_index << "...\n";
	fo.open(out_fil_index);
	fo.printf("<html><head><title>mrpt-performance results - Index</title>\n"
			"<style type=\"text/css\"><!--\n"
			".my_rotated {\n"
			"     -moz-transform: rotate(-90deg);  /* FF3.5+ */\n"
			"       -o-transform: rotate(-90deg);  /* Opera 10.5 */\n"
			"  -webkit-transform: rotate(-90deg);  /* Saf3.1+, Chrome */\n"
			"             filter:  progid:DXImageTransform.Microsoft.BasicImage(rotation=-1.57079632679490);  /* IE6,IE7 */\n"
			"         -ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=-1.57079632679490)\"; /* IE8 */\n"
			"}\n"
			"--></style>\n"
			"</head>\n"
	          "<body style=\"background-color:#E6E6FA\">\n\n");
	fo.printf("<h2>Performance reports</h2><hr>\n");

	fo.printf("<br>\n"
	          "This is a historic repository of performance tests executed against the MRPT libraries along time.\n"
	          "Each entry represents a different MRPT version, different compilers or architectures."
	          "Below follows the list of available performance tests (see also the <a href=\"#matrix\">comparison tables matrix</a>):<br>\n"
	          "<ul>\n");

	for (size_t i=0;i<lstConfigurations.size();i++)
	{
		const TPerfField &P = lstConfigurations[i];
		fo.printf("<li>"
				  "<a href=\"results_%s.html\">%s</a>"
				  "</li>\n",
				  P.config_name.c_str(),
				  P.config_name.c_str()
				  );
	}

	fo.printf("</ul>\n");


	fo.printf("<a name=\"matrix\"> </a>\n");
	fo.printf("<h2>Comparison matrix</h2><hr>\n");

	// Build the matrix:
	// Only fills the lower triangle matrix entries.
	fo.printf("<div align=\"center\" ><table border=\"1\">\n");
	for (size_t i=0;i<lstConfigurations.size();i++)
	{
		const TPerfField &P1 = lstConfigurations[i];
		fo.printf(" <tr><td align=\"right\"><b>%s</b></td>", P1.config_name.c_str() );

		for (size_t j=0;j<lstConfigurations.size();j++)
		{
			const TPerfField &P2 = lstConfigurations[j];
//			if (j>i)
//			{
//				fo.printf("  <td border=\"0\"></td>\n");
//				continue;
//			}
			string txt;
			if (i==j)
			{
				txt = "&empty;";
			}
			else
			{
				txt = format("<a href=\"comparison_%s_vs_%s.html\">&#9745;</a>",
							P1.config_name.c_str(),
							P2.config_name.c_str() );
			}
			fo.printf("  <td align=\"center\">%s</td>\n",txt.c_str());
		}
		fo.printf(" </tr>\n");
	}
	// and the last row:
	fo.printf(" <tr>\n" );
	fo.printf("  <td></td>\n" );
	for (size_t i=0;i<lstConfigurations.size();i++)
	{
		const TPerfField &P1 = lstConfigurations[i];
		// class=\"my_rotated\"
		fo.printf("<td align=\"center\" width=\"20em\"><b><div >%s</div></b></td>", P1.config_name.c_str() );
	}
	fo.printf(" </tr>\n" );
	fo.printf("</table></div>\n");


	fo.printf("<hr><small>Page generated automatically at %s with %s by 'mrpt-performance'.</small>\n",mrpt::system::dateTimeLocalToString(now()).c_str(), MRPT_getVersion().c_str() );
	fo.printf("</body></html>\n");
	fo.close();


	// ====================================================
	//        results_<cfg>.html
	// ====================================================
	for (size_t i=0;i<lstConfigurations.size();i++)
	{
		const TPerfField &P = lstConfigurations[i];
		const string out_fil = PERF_DATA_DIR+format("/perf-html/results_%s.html",P.config_name.c_str());
		cout << "Generating: " << out_fil << "...\n";
		CFileOutputStream  fo(out_fil);

		fo.printf("<html><head><title>mrpt-performance results - Configuration: %s</title></head>\n"
				  "<body style=\"background-color:#E6E6FA\">\n\n",
				  P.config_name.c_str() );

		fo.printf("<div align=\"center\"><h2>Results for: %s</h2></div>", P.config_name.c_str() );
		fo.printf("<hr> <br><br>\n");

		fo.printf("<div align=\"center\"><table border=\"1\">\n");
		fo.printf("<tr> <td align=\"center\"><b>Test description</b></td> "
				  "<td align=\"center\"><b>Execution time</b></td>"
				  "<td align=\"center\"><b>Execution rate (Hz)</b></td> </tr>\n");

		for (size_t j=0;j<P.all_perf_data.size();j++)  // vector<pair<string,double> >
		{
			const double t = P.all_perf_data[j].second;
			fo.printf("<tr> <td>%s</td> <td align=\"right\">%s</td> <td align=\"right\">%sHz</td>  </tr>\n",
				P.all_perf_data[j].first.c_str(),
				mrpt::system::intervalFormat(t).c_str(),
				mrpt::system::unitsFormat(1.0/t).c_str());
		}

		fo.printf("</table></div>\n");
		fo.printf("<p> &nbsp; </p>\n");

		fo.printf("<hr><small>Page generated automatically at %s with %s by 'mrpt-performance'.</small>\n",mrpt::system::dateTimeLocalToString(now()).c_str(), MRPT_getVersion().c_str() );
		fo.printf("</body></html>\n");

	} // for each perf


	// --------------------------------------
	//  COMPARISON TABLES
	// --------------------------------------
	for (size_t i=0;i<lstConfigurations.size();i++)
	{
		TPerfField P1 = lstConfigurations[i];
		for (size_t j=0;j<lstConfigurations.size();j++)
		{
			TPerfField P2 = lstConfigurations[j];
			if (j==i)  continue;
			const string out_fil = PERF_DATA_DIR+format("/perf-html/comparison_%s_vs_%s.html",
							P1.config_name.c_str(),
							P2.config_name.c_str() );

			cout << "Generating: " << out_fil << "...\n";


			// Make sure P1 is the "more modern" version:
//			if ( P1.config_name < P2.config_name )
//				std::swap(P1,P2);

			// Convert P2 data into a std::map<> for search efficiency:
			map<string,double>  P2_dat;
			for (size_t k=0;k<P2.all_perf_data.size();k++)
				P2_dat[P2.all_perf_data[k].first] = P2.all_perf_data[k].second;

			CFileOutputStream  fo(out_fil);

			fo.printf("<html><head><title>mrpt-performance results - %s vs %s</title></head>\n"
					  "<body style=\"background-color:#E6E6FA\">\n\n",
					  P1.config_name.c_str(),P2.config_name.c_str() );

			fo.printf("<div align=\"center\"><h2>Comparison: %s vs. %s</h2></div>", P1.config_name.c_str(), P2.config_name.c_str() );
			fo.printf("<hr> <br><br>\n");

			fo.printf("<div align=\"center\"><table border=\"1\">\n");
			fo.printf("<tr> <td rowspan=\"2\" align=\"center\"><b>Test description</b></td> "
					  "<td colspan=\"4\" align=\"center\"><b>%s / <div style=\"color:gray;\">%s</div></b></td>"
					  "</tr>"
					  "<tr>"
					  "<td colspan=\"2\" align=\"center\"><b>Execution time</b></td>"
					  "<td colspan=\"2\" align=\"center\"><b>Execution rate (Hz)</b></td> </tr>\n",
						P1.config_name.c_str(),P2.config_name.c_str()
					  );

			for (size_t k=0;k<P1.all_perf_data.size();k++)  // vector<pair<string,double> >
			{
				const double t1 = P1.all_perf_data[k].second;
				const string test_name = P1.all_perf_data[k].first;

				const bool P2_has_this_one = P2_dat.find(test_name)!=P2_dat.end();

				string str_secs, str_secs_res;
				string str_Hz, str_Hz_res;

				if (!P2_has_this_one)
				{
					str_secs = format("%s / <div style=\"color:gray;\">X</div>",
						mrpt::system::intervalFormat(t1).c_str()  );
					str_Hz = format("%sHz / <div style=\"color:gray;\">X</div>",
						mrpt::system::unitsFormat(1.0/t1).c_str() );
				}
				else
				{
					const double t2 = P2_dat[test_name];
					str_secs = format("%s / <div style=\"color:gray;\">%s</div>",
						mrpt::system::intervalFormat(t1).c_str(),
						mrpt::system::intervalFormat(t2).c_str() );

					const double At = t1-t2;
					str_secs_res = format("<div style=\"color:%s;\">%s %.02f%%</div>",
						At>0 ? "red":"blue",
						At>0 ? "&Delta;" : "&nabla;",
						100*At/t2
						);

					str_Hz = format("%sHz / <div style=\"color:gray;\">%sHz</div>",
						mrpt::system::unitsFormat(1.0/t1).c_str(),
						mrpt::system::unitsFormat(1.0/t2).c_str());

					const double AHz = 1.0/t1-1.0/t2;
					str_Hz_res = format("<div style=\"color:%s;\">%s %.02f%%</div>",
						AHz>0 ? "blue":"red",
						AHz>0 ? "&Delta;" : "&nabla;",
						100*AHz/(1.0/t2)
						);
				}

				fo.printf("<tr> <td>%s</td>"
				          "<td align=\"right\">%s</td>"
				          "<td align=\"center\">%s</td>"
				          "<td align=\"right\">%s</td>"
				          "<td align=\"center\">%s</td>"
				          "</tr>\n",
				          test_name.c_str(),
						  str_secs.c_str(), str_secs_res.c_str(),
						  str_Hz.c_str(), str_Hz_res.c_str() );
			}


			fo.printf("</table></div>\n");
			fo.printf("<p> &nbsp; </p>\n");

			fo.printf("<hr><small>Page generated automatically at %s with %s by 'mrpt-performance'.</small>\n",mrpt::system::dateTimeLocalToString(now()).c_str(), MRPT_getVersion().c_str() );
			fo.printf("</body></html>\n");
		}
	}


	return 0;
}
Exemple #5
0
void enum_and_print_start(CFileOutputStream& out, wchar_t* szDir)
{
	out.Write(szDir);
	out.Write(L"\n");
	enum_and_print(out, szDir, 1);
}