コード例 #1
0
    string cpu_time_t::to_s(const char *_fpformat) const {
        if (_fpformat == 0)
            _fpformat = "%.5lg%s";

        double t = seconds();

        if (t < 9.9999e-9) { // nanoseconds
            return formatf(_fpformat, t * 1e9, "ns");
        }
        if (t < 9.9999e-6) { // microseconds
            return formatf(_fpformat, t * 1e6, "us");
        }
        else if (t < 0.099999) { // milliseconds
            return formatf(_fpformat, t * 1000.0, "ms");
        } else if (t < 300.0) {
            return formatf(_fpformat, t, "s");
        }

        const double h1 = 3600.0;
        const double h2 = 2.0 * 3600.0;
        const double d1 = 24.0 * 3600.0;
        const double d2 = 48.0 * 3600.0;


        if (t >= d2) { // days
            double d = floor(t / d1);
            t -= d * d1;
            double h = floor(t / h1);
            t -= h * h1;
            double m = floor(t / 60.0);
            t -= m * 60.0;
            double s = t;
            return formatf("%dd:%dh:%dm:%lg.2s", int(d), int(h), int(m), s);
        }
        else if (t >= h2) { // hours
            double h = floor(t / h1);
            t -= h * h1;
            double m = floor(t / 60.0);
            t -= m * 60.0;
            double s = t;
            return formatf("%dh:%dm:%lg.2s", int(h), int(m), s);
        }
        else if (t >= 300.0) { // minutes
            double m = floor(t / 60.0);
            t -= m * 60.0;
            double s = t;
            return formatf("%dm:%.2lgs", int(m), s);
        }

        assert("!unreachable");
        return formatf(_fpformat, t, "s"); // has been tested before (see above)
    }
コード例 #2
0
 cpu_time_diff_t StopWatch::toc(std::ostream &_os, const char *_msg) {
     cpu_time_diff_t dt = toc();
     _os << formatf(_msg, dt.to_s().c_str());
     return dt;
 }
コード例 #3
0
ファイル: interactive.c プロジェクト: kusumi/DragonFlyBSD
/*
 * Do an "ls" style listing of a directory
 */
static void
printlist(const char *name, char *basename)
{
	struct afile *fp, *list, *listp = NULL;
	struct direct *dp;
	struct afile single;
	RST_DIR *dirp;
	int entries, len, namelen;
	char locname[MAXPATHLEN + 1];

	dp = pathsearch(name);
	if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
	    (!vflag && dp->d_ino == UFS_WINO))
		return;
	if ((dirp = rst_opendir(name)) == NULL) {
		entries = 1;
		list = &single;
		mkentry(name, dp, list);
		len = strlen(basename) + 1;
		if (strlen(name) - len > (unsigned short)single.len) {
			freename(single.fname);
			single.fname = savename(&name[len]);
			single.len = strlen(single.fname);
		}
	} else {
		entries = 0;
		while ((dp = rst_readdir(dirp)))
			entries++;
		rst_closedir(dirp);
		list = (struct afile *)malloc(entries * sizeof(struct afile));
		if (list == NULL) {
			fprintf(stderr, "ls: out of memory\n");
			return;
		}
		if ((dirp = rst_opendir(name)) == NULL)
			panic("directory reopen failed\n");
		fprintf(stderr, "%s:\n", name);
		entries = 0;
		listp = list;
		strncpy(locname, name, MAXPATHLEN);
		strncat(locname, "/", MAXPATHLEN);
		namelen = strlen(locname);
		while ((dp = rst_readdir(dirp))) {
			if (dp == NULL)
				break;
			if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)
				continue;
			if (!vflag && (dp->d_ino == UFS_WINO ||
			     strcmp(dp->d_name, ".") == 0 ||
			     strcmp(dp->d_name, "..") == 0))
				continue;
			locname[namelen] = '\0';
			if (namelen + dp->d_namlen >= MAXPATHLEN) {
				fprintf(stderr, "%s%s: name exceeds %d char\n",
					locname, dp->d_name, MAXPATHLEN);
			} else {
				strncat(locname, dp->d_name, (int)dp->d_namlen);
				mkentry(locname, dp, listp++);
				entries++;
			}
		}
		rst_closedir(dirp);
		if (entries == 0) {
			fprintf(stderr, "\n");
			free(list);
			return;
		}
		qsort((char *)list, entries, sizeof(struct afile), fcmp);
	}
	formatf(list, entries);
	if (dirp != NULL) {
		for (fp = listp - 1; fp >= list; fp--)
			freename(fp->fname);
		fprintf(stderr, "\n");
		free(list);
	}
}