Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <vcl_cerrno.h>
00008 #include <vcl_string.h>
00009 #include <vcl_fstream.h>
00010 #include <vcl_ctime.h>
00011 #include <vcl_cstdlib.h>
00012 #include <vul/vul_file.h>
00013 #include <vul/vul_expand_path.h>
00014 #include <mbl/mbl_config.h>
00015
00016
00017
00018 static unsigned replace(char from, char to, vcl_string &s)
00019 {
00020 unsigned c = 0;
00021 for (unsigned i=0; i<s.size(); ++i)
00022 if (s[i] == from)
00023 {
00024 c++;
00025 s[i] = to;
00026 }
00027 return c;
00028 }
00029
00030
00031 vcl_string timestamp()
00032 {
00033 char tmpbuf[128];
00034 vcl_time_t ltime;
00035 struct vcl_tm *today;
00036
00037
00038 vcl_time( <ime );
00039
00040
00041 today = vcl_localtime( <ime );
00042
00043
00044 vcl_strftime( tmpbuf, 128,
00045 "%Y-%m-%d %H:%M:%S", today );
00046 return vcl_string(tmpbuf);
00047 }
00048
00049
00050
00051
00052
00053
00054 void mbl_test_save_measurement( const vcl_string &measurement_path, double value)
00055 {
00056 vcl_cout << "<DartMeasurement name=\"" <<
00057 vul_file::strip_directory(measurement_path) <<
00058 "\" type=\"numeric/float\">"<<value<<"</DartMeasurement>" << vcl_endl;
00059
00060 char * cpath = vcl_getenv("MBL_TEST_SAVE_MEASUREMENT_ROOT");
00061 vcl_string path(cpath?cpath:"");
00062 if (path.empty())
00063 path = MBL_CONFIG_TEST_SAVE_MEASUREMENT_ROOT;
00064 if (path.empty())
00065 return;
00066
00067 vcl_string config = MBL_CONFIG_BUILD_NAME;
00068 if (config.empty()) config="DEFAULT_CONFIG";
00069
00070 path += '/' + measurement_path + ".txt";
00071 replace('\\', '/', path);
00072 path = vul_expand_path(path);
00073 vul_file::make_directory_path(vul_file::dirname(path));
00074 vcl_ofstream file(path.c_str(), vcl_ios_app | vcl_ios_out);
00075
00076 if (!file)
00077 vcl_cerr << "ERROR: mbl_test_save_measurement: Unable to open file " << path.c_str() <<
00078 "ERRNO: " << errno << vcl_endl;
00079 else
00080 file << timestamp() << ' ' << MBL_CONFIG_BUILD_NAME << ' ' << value << vcl_endl;
00081 }