Пример #1
0
  sp<Retval> MonDiskstats::readData(){
      sp<Retval> retval;

      String sContents;
      String sLine;
      if( DFW_RET(retval, File::contents(sContents, source_path())) )
          return DFW_RETVAL_D(retval);
      if( sContents.length()==0 )
          return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0
                     ,"Has not contents at %s", source_path());

      unsigned len;
      const char* lp;
      const char* p = sContents.toChars();
      do{
          if( p == NULL )
              break;
          if( (lp = strstr(p, "\n")) == NULL )
              break;
          if( (len = lp - p) == 0 )
              break;
          sLine.set(p, len);
          p += len + 1;

          if( DFW_RET(retval, parseLine(sLine)) ){
              // FIXME:
printf("%s\n", retval->dump().toChars());
          }
      }while(true);

      return NULL;      
  }
Пример #2
0
WrapperStr UmlPackage::header_path(const WrapperStr & f)
{
    if (!dir.read) {
        source_path(f);

        if (dir.h.isEmpty()) {
            UmlCom::trace(WrapperStr("<font color=\"red\"><b><b> The generation directory "
                                    "must be specified for the package<i> ") + name()
                          + "</i>, edit the <i> generation settings</i> (tab 'directory') "
                          "or edit the package (tab 'C++')</b></font><br>");
            UmlCom::bye(n_errors() + 1);
            UmlCom::fatal_error("UmlPackage::source_path");
        }

        if (QDir::isRelativePath(dir.h)) {
            UmlCom::trace(WrapperStr("<font color=\"red\"><b><i>")
                          + name() + "</i>'s header path <i>(" + dir.h
                          + "</i>) is not absolute, edit the <i> generation settings</i> "
                          "(tab 'directory'), or edit the package (tab 'C++')</b></font><br>");
            UmlCom::bye(n_errors() + 1);
            UmlCom::fatal_error("UmlPackage::source_path");
        }
    }

    QDir d(dir.h);

    return WrapperStr(d.filePath(f).toLatin1().constData()) + WrapperStr(".") + CppSettings::headerExtension();
}
Пример #3
0
  sp<Retval> MonPacket::parseTitle(String& sLine)
  {
      sp<Retval> retval;

      if( N_HAS )
          return NULL;

      StringArray sa1;
      sa1.split(sLine, "|");
      if(sa1.size()!=3){
          return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0
                     , "Unknown format %s", source_path());
      }

      int all, all2;
      sp<String> s1 = sa1.getString(1);
      if( DFW_RET(retval, parseTitle_l(s1, &all
                        , &N_R_BYTES, &N_R_PACKETS, &N_R_ERRS)) )
          return DFW_RETVAL_D(retval);

      sp<String> s2 = sa1.getString(2);
      if( DFW_RET(retval, parseTitle_l(s2, &all2
                        , &N_T_BYTES, &N_T_PACKETS, &N_T_ERRS)) )
          return DFW_RETVAL_D(retval);

      N_T_BYTES += all;
      N_T_PACKETS += all;
      N_T_ERRS += all;
      N_HAS = true;
      return NULL;
  }
Пример #4
0
void repository::cache::unpack_source(
    const entry &package, const std::string &source_id,
    const boost::filesystem::path &destination) {
  try {
    distributor_().archiver().unpack(source_path(package, source_id),
                                     destination);
  } catch (std::exception &) {
    BOOST_THROW_EXCEPTION(cache_unpack_source_error()
                          << cache_unpack_source_error::package(package)
                          << cache_unpack_source_error::destination(destination)
                          << enable_nested_current());
  }
}
Пример #5
0
  sp<Retval> MonPacket::readData(){
      sp<Retval> retval;

      String sContents;
      String sLine;
      if( DFW_RET(retval, File::contents(sContents, source_path())) )
          return DFW_RETVAL_D(retval);
      if( sContents.length()==0 )
          return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0
                     ,"Has not contents at %s", source_path());

      unsigned len;
      const char* lp;
      const char* p = sContents.toChars();
      int round = 0;
      do{
          if( p == NULL )
              break;
          if( (lp = strstr(p, "\n")) == NULL )
              break;
          if( (len = lp - p) == 0 )
              break;
          sLine.set(p, len);
          p += len + 1;

          if( round == 0 ){
          }else if( round == 1 && DFW_RET(retval, parseTitle(sLine)) ){
              return DFW_RETVAL_D(retval);
          }else if( round > 1 && DFW_RET(retval, parseLine(sLine)) ){
              return DFW_RETVAL_D(retval);
          }

          round++;
      }while(true);

      return NULL;
  }
Пример #6
0
  sp<Retval> MonPacket::parseTitle_l(sp<String>& s
                         , int* all, int* bytes, int* packets, int* errs)
  {
      int find = 0;
      int c = 0;
      String sVal;
      const char* p = s->toChars();
      do{
          if( (*p) == '\0' ) { break; }
          if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; }

          const char* b = ::strstr(p, " ");
          if( !b ) {
              sVal.set(p);
          }else{
              sVal.set(p, b-p);
          }

          p += sVal.length();

          //bytes    packets errs drop fifo frame compressed multicast
          //bytes    packets errs drop fifo colls carrier compressed
          if( sVal.equals("bytes") ){
              *bytes = c;
              find++;
          }else if( sVal.equals("packets") ){
              *packets = c;
              find++;
          }else if( sVal.equals("errs") ){
              *errs = c;
              find++;
          }

          c++;
      }while(true);

      if( find == 3 ){
          *all = c;
          return NULL;
      }
      return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0
                 , "Not find need format (%s)", source_path());
  }
Пример #7
0
WrapperStr UmlPackage::header_path(const WrapperStr & f, WrapperStr relto)
{
    if (!dir.read) {
        source_path(f);

        if (dir.h.isEmpty()) {
            UmlCom::trace(WrapperStr("<font color=\"red\"><b><b> The generation directory "
                                    "must be specified for the package<i> ") + name()
                          + "</i>, edit the <i> generation settings</i> (tab 'directory') "
                          "or edit the package (tab 'C++')</b></font><br>");
            UmlCom::bye(n_errors() + 1);
            UmlCom::fatal_error("UmlPackage::source_path");
        }

        if (QDir::isRelativePath(dir.h)) {
            UmlCom::trace(WrapperStr("<font color=\"red\"><b><i>")
                          + name() + "</i>'s header path <i>(" + dir.h
                          + "</i>) is not absolute, edit the <i> generation settings</i> "
                          "(tab 'directory'), or edit the package (tab 'C++')</b></font><br>");
            UmlCom::bye(n_errors() + 1);
            UmlCom::fatal_error("UmlPackage::source_path");
        }
    }

    if (f.isEmpty())
        return dir.h;

    QDir d(dir.h);

    if (! d.exists())
        create_directory(dir.h);	// don't return on error
    QByteArray temp = d.filePath(f).toLatin1();

    WrapperStr df = (dir.h_absolute || relto.isEmpty())
                   ? WrapperStr(temp.constData())
                   : relative_path(d, relto) + f;

    return df + WrapperStr(".") + CppSettings::headerExtension();
}
Пример #8
0
WrapperStr UmlPackage::text_path(const WrapperStr & f, WrapperStr relto)
{
    WrapperStr r = source_path(f, relto);

    return r.left(r.length() - 1 - CppSettings::sourceExtension().length());
}
Пример #9
0
int main(int argc, char** argv) {

    try {
        std::ostringstream oss;
        oss << "Usage: " << argv[0] << " ACTION [additional options]";
        po::options_description desc(oss.str());
        desc.add_options()
                ("help,h", "produce help message")
                ("version,v", "print libklio version and exit")
                ("action,a", po::value<std::string>(), "Valid actions are: create, check, sync, upgrade")
                ("storefile,s", po::value<std::string>(), "the data store to use")
                ("sourcestore,r", po::value<std::string>(), "the data store to use as source for synchronization")
                ;
        po::positional_options_description p;
        p.add("action", 1);
        p.add("storefile", 1);

        po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).
                options(desc).positional(p).run(), vm);
        po::notify(vm);

        // Begin processing of command line parameters.
        std::string action;
        std::string storefile;

        if (vm.count("help")) {
            std::cout << desc << std::endl;
            return 0;
        }

        if (vm.count("version")) {
            klio::VersionInfo::Ptr vi(new klio::VersionInfo());
            std::cout << "klio library version " << vi->getVersion() << std::endl;
            return 0;
        }

        if (!vm.count("storefile")) {
            std::cerr << "You must specify a store to work on." << std::endl;
            return 1;
        } else {
            storefile = vm["storefile"].as<std::string>();
        }

        if (!vm.count("action")) {
            std::cerr << "You must specify an action." << std::endl;
            return 1;
        } else {
            action = (vm["action"].as<std::string>());
        }

        klio::StoreFactory::Ptr factory(new klio::StoreFactory());
        bfs::path db(storefile);
        
        /**
         * CREATE action
         */
        if (boost::iequals(action, std::string("create"))) {

            if (bfs::exists(db)) {
                std::cerr << "File " << db << " already exists, exiting." << std::endl;
                return 2;
            }

            try {
                std::cout << "Attempting to create " << db << std::endl;
                klio::Store::Ptr store(factory->create_sqlite3_store(db));
                std::cout << "Initialized store: " << store->str() << std::endl;

            } catch (klio::StoreException const& ex) {
                std::cout << "Failed to create: " << ex.what() << std::endl;
                return 1;
            }

            /**
             * CHECK action
             */
        } else if (boost::iequals(action, std::string("check"))) {

            if (!bfs::exists(db)) {
                std::cerr << "File " << db << " does not exist, exiting." << std::endl;
                return 2;
            }

            try {
                std::cout << "Attempting to open " << db << std::endl;
                klio::Store::Ptr store(factory->open_sqlite3_store(db));
                std::cout << "opened store: " << store->str() << std::endl;

                std::vector<klio::Sensor::uuid_t> uuids = store->get_sensor_uuids();
                std::vector<klio::Sensor::uuid_t>::iterator it;
                klio::timestamp_t all_sensors_last_timestamp = 0;
                // First pass: get the latest timestamps of all sensors
                std::cout << "First pass: get the latest timestamps of all sensors" << db << std::endl;

                for (it = uuids.begin(); it < uuids.end(); it++) {
                  klio::Sensor::Ptr loadedSensor(store->get_sensor(*it));
                  klio::reading_t last_reading = store->get_last_reading(loadedSensor);
                  all_sensors_last_timestamp = std::max(all_sensors_last_timestamp, last_reading.first);
                }
                std::cout << std::setw(5) << "stat";
                std::cout << std::setw(8) << "# val";
                std::cout << std::setw(8) << "dt med";
                std::cout << std::setw(8) << "dt min";
                std::cout << std::setw(8) << "dt max";
                std::cout << std::setw(8) << "avg(W)";
                std::cout << std::setw(8) << "min(W)";
                std::cout << std::setw(8) << "max(W)";
                std::cout << std::setw(21) << "first timestamp";
                std::cout << std::setw(21) << "last timestamp";
                std::cout << '\t' << "type";
                std::cout << std::setw(8) << "unit";

                std::cout << '\t' << "sensor name / description" << std::endl;
                for (it = uuids.begin(); it < uuids.end(); it++) {

                    klio::Sensor::Ptr loadedSensor(store->get_sensor(*it));
                    klio::readings_t_Ptr readings;
                    readings = store->get_all_readings(loadedSensor);

                    // loop over all readings and calculate metrics
                    uint64_t num_readings = 0;
                    klio::timestamp_t first_timestamp = 0;
                    klio::timestamp_t last_timestamp = 0;
                    uint32_t min_timestamp_interval = std::numeric_limits<uint32_t>::max();
                    uint32_t max_timestamp_interval = std::numeric_limits<uint32_t>::min();
                    double min_value = std::numeric_limits<double>::max();
                    double max_value = std::numeric_limits<double>::min();
                    double aggregated_value = 0;

                    std::vector<uint32_t> all_intervals;

                    for (klio::readings_it_t it = readings->begin();
                            it != readings->end(); it++) {

                        num_readings++;
                        klio::timestamp_t ts1 = (*it).first;
                        double val1 = (*it).second;
                        min_value = std::min(min_value, val1);
                        max_value = std::max(max_value, val1);
                        aggregated_value += val1;

                        if (last_timestamp == 0) {
                            // this is the first value we read, initialize state
                            first_timestamp = ts1;
                            last_timestamp = ts1;
                            
                        } else {
                            // everything set up, this is just another value
                            uint32_t interval = ts1 - last_timestamp;
                            all_intervals.push_back(interval);
                            min_timestamp_interval = std::min(min_timestamp_interval, interval);
                            max_timestamp_interval = std::max(max_timestamp_interval, interval);
                            // Update state variables
                            last_timestamp = ts1;
                        }
                    }
                    
                    size_t middle_element_idx = all_intervals.size() / 2;
                    uint32_t mean_interval = 0;

                    if (middle_element_idx != 0) {
                        std::nth_element(all_intervals.begin(),
                                all_intervals.begin() + middle_element_idx,
                                all_intervals.end());
                        mean_interval = all_intervals[middle_element_idx];
                    }

                    // compose output line
                    std::ostringstream stat_oss;
                    if (last_timestamp + (60*60) < all_sensors_last_timestamp) {
                      // no value in the last hour - mark as late
                      stat_oss << "L"; // mark as late
                    } else {
                      stat_oss << "C"; // mark as current
                    }
                    std::cout << std::setfill(' ') << std::setw(5) << stat_oss.str();
                    std::cout << std::setw(8) << num_readings;
                    std::cout << std::setw(8) << mean_interval;
                    
                    // print mean of intervals
                    if (min_timestamp_interval == std::numeric_limits<uint32_t>::max() ||
                            max_timestamp_interval == std::numeric_limits<uint32_t>::min()) {

                        std::cout << std::setw(8) << "n/a";
                        std::cout << std::setw(8) << "n/a";

                    } else {
                        std::cout << std::setw(8) << min_timestamp_interval;
                        std::cout << std::setw(8) << max_timestamp_interval;
                    }
                    
                    // value stats
                    if (num_readings == 0) {
                        std::cout << std::setw(8) << "n/a";

                    } else {
                        std::cout << std::setw(8) << (uint32_t) aggregated_value / num_readings;
                    }
                    std::cout << std::setw(8) << (uint32_t) min_value;
                    std::cout << std::setw(8) << (uint32_t) max_value;

                    // Time conversion foo
                    klio::LocalTime::Ptr lt(new klio::LocalTime("."));
                    boost::local_time::local_time_facet* output_facet
                            = new boost::local_time::local_time_facet();
                    output_facet->format("%Y.%m.%d-%H:%M:%S");

                    std::ostringstream oss;
                    oss.imbue(std::locale(std::locale::classic(), output_facet));
                    boost::local_time::local_date_time first_timestamp_datetime =
                            lt->get_local_time(loadedSensor, first_timestamp);
                    oss.str("");
                    oss << first_timestamp_datetime;
                    std::cout << std::setw(21) << oss.str();

                    boost::local_time::local_date_time last_timestamp_datetime =
                            lt->get_local_time(loadedSensor, last_timestamp);
                    oss.str("");
                    oss << last_timestamp_datetime;
                    std::cout << std::setw(21) << oss.str();
                    // sensor data
                    std::cout << '\t' << loadedSensor->device_type()->name();

                    // unit
                    std::cout << '\t' << loadedSensor->unit();

                    // name and description
                    std::cout << '\t' << loadedSensor->name();
                    std::cout << '\t' << loadedSensor->description();

                    // for debugging only: external_id
                    //std::cout << '\t' << '#' << loadedSensor->external_id();

                    std::cout << std::endl;
                }
            } catch (klio::StoreException const& ex) {
                std::cout << "Failed to check: " << ex.what() << std::endl;
                return 1;
            }

            /**
             * SYNC action
             */
        } else if (boost::iequals(action, std::string("sync"))) {

            std::string sourcestore;

            if (!vm.count("sourcestore")) {
                std::cerr << "You must specify a source store for synchronization." << std::endl;
                return 1;

            } else {
                sourcestore = vm["sourcestore"].as<std::string>();
            }

            bfs::path source_path(sourcestore);
            if (!bfs::exists(source_path)) {
                std::cerr << "File " << source_path << " does not exist, exiting." << std::endl;
                return 2;
            }
            bfs::path target_path(storefile);
            if (!bfs::exists(target_path)) {
                std::cerr << "File " << target_path << " does not exist, exiting." << std::endl;
                return 2;
            }

            try {
                std::cout << "Attempting to open source store " << source_path << std::endl;
                klio::Store::Ptr source_store(factory->open_sqlite3_store(source_path));
                std::cout << "Opened source store: " << source_store->str() << std::endl;

                std::cout << "Attempting to open target store " << target_path << std::endl;
                klio::Store::Ptr target_store(factory->open_sqlite3_store(target_path));
                std::cout << "Opened target store: " << target_store->str() << std::endl;

                std::cout << "Synchronizing stores..." << std::endl;
                target_store->sync(source_store);
                std::cout << "Stores Synchronized." << std::endl;

                source_store->close();
                target_store->close();

            } catch (klio::StoreException const& ex) {
                std::cout << "Failed to synchronize stores. " << ex.what() << std::endl;
                return 1;
            }

            /**
             * UPGRADE action
             */
        } else if (boost::iequals(action, std::string("upgrade"))) {

            try {
                klio::VersionInfo::Ptr info = klio::VersionInfo::Ptr(new klio::VersionInfo());

                std::cout << "Attempting to upgrade " << db << " to version " << info->getVersion() << std::endl;
                klio::SQLite3Store::Ptr store(factory->create_sqlite3_store(db, false));
                store->upgrade();
                std::cout << "Store upgraded." << std::endl;

            } catch (klio::StoreException const& ex) {
                std::cout << "Failed to upgrade: " << ex.what() << std::endl;
                return 1;
            }

            /** 
             * unknown command
             */
        } else {
            std::cerr << "Unknown command " << action << std::endl;
            return 1;
        }

    } catch (std::exception& e) {
        std::cerr << "error: " << e.what() << std::endl;
        return 1;

    } catch (...) {
        std::cerr << "Exception of unknown type!" << std::endl;
        return 1;
    }

    return 0;
}
Пример #10
0
void ShaderCompiler::compilePass(const char* shd_path,
	bool is_vertex_shader,
	const char* pass,
	int define_mask,
	const Lumix::ShaderCombinations::Defines& all_defines)
{
	const char* base_path = m_editor.getEngine().getDiskFileDevice()->getBasePath();
	bool is_opengl = getRenderer().isOpenGL();

	for (int mask = 0; mask < 1 << Lumix::lengthOf(all_defines); ++mask)
	{
		if ((mask & (~define_mask)) == 0)
		{
			updateNotifications();
			char basename[Lumix::MAX_PATH_LENGTH];
			Lumix::PathUtils::getBasename(basename, sizeof(basename), shd_path);
			Lumix::StaticString<Lumix::MAX_PATH_LENGTH> source_path (
				"\"shaders/", basename, is_vertex_shader ? "_vs.sc\"" : "_fs.sc\"");
			char out_path[Lumix::MAX_PATH_LENGTH];
			Lumix::copyString(out_path, base_path);
			Lumix::catString(out_path, "/shaders/compiled");
			Lumix::catString(out_path, is_opengl ? "_gl/" : "/");
			Lumix::catString(out_path, basename);
			Lumix::catString(out_path, "_");
			Lumix::catString(out_path, Lumix::StaticString<30>(pass, mask));
			Lumix::catString(out_path, is_vertex_shader ? "_vs.shb" : "_fs.shb");

			Lumix::StaticString<1024> args(" -f ");

			args << source_path << " -o \"" << out_path << "\" --depends ";
			if (getRenderer().isOpenGL())
			{
				args << "--platform linux --profile 140 ";
			}
			else
			{
				args << "--platform windows " << (is_vertex_shader ? "--profile vs_5_0" : "--profile ps_5_0");
			}
			args << " --type "
				<< (is_vertex_shader ? "vertex -O3" : "fragment -O3")
				<< " --define " << pass << ";";
			for (int i = 0; i < Lumix::lengthOf(all_defines); ++i)
			{
				if (mask & (1 << i))
				{
					args << getRenderer().getShaderDefine(all_defines[i]) << ";";
				}
			}

			#ifdef _WIN32
				Lumix::StaticString<Lumix::MAX_PATH_LENGTH> cmd(base_path, "/shaders/shaderc.exe");
			#elif defined __linux__
				Lumix::StaticString<Lumix::MAX_PATH_LENGTH> cmd(base_path, "/shaders/shaderc");
			#else
				#error Platform not supported
			#endif
			
			PlatformInterface::deleteFile(out_path);
			auto* process = PlatformInterface::createProcess(cmd, args, m_editor.getAllocator());
			if (!process)
			{
				Lumix::g_log_error.log("Editor") << "Could not execute command: " << cmd;
			}
			else
			{
				auto& p = m_processes.emplace();
				p.process = process;
				Lumix::copyString(p.path, out_path);
			}
		}
	}
}