Esempio n. 1
0
func MakeSrcsPngContent(d db.DB, b *bytes.Buffer, rawQuery string) error {
	dTable, err := getDataTable(d, rawQuery)
	if err != nil {
		return err
	}

	q, _ := url.ParseQuery(rawQuery)
	widthStr := q.Get("w")
	width := float64(defaultPngWidth)
	if widthStr != "" {
		var err error
		width, err = strconv.ParseFloat(widthStr, 64)
		if err != nil {
			return errors.New("Cannot parse width parameter w: " + err.Error())
		}
	}

	heightStr := q.Get("h")
	height := float64(defaultPngHeight)
	if heightStr != "" {
		var err error
		height, err = strconv.ParseFloat(heightStr, 64)
		if err != nil {
			return errors.New("Cannot parse height parameter h: " + err.Error())
		}
	}

	// TODO: Don't call this again since getDataTable() already did.
	req, err := requests.MakeRowRangeReqs(rawQuery)
	if err != nil {
		return err
	}

	// TODO: Write ticker functions to work for equalX, sortByColumn, and
	//       sortByConfig.  Use in dataTableToPng().
	xLabel := req.SortByColumn
	if req.EqualX {
		xLabel = common.RecordNumName
	} else if req.SortByConfig != "" {
		xLabel = req.SortByConfig
	}

	var srcs []string
	for _, fs := range req.FilteredSources {
		srcs = append(srcs, fs.Source)
	}
	title := strings.Join(srcs, ", ")

	png.DataTableToPng(b, dTable, title, width, height, xLabel)
	return nil
}
Esempio n. 2
0
// getDataTable returns a db.Datatable with the X-axis as specified and rows
// sorted by the X-axis.
func getDataTable(D db.DB, rawQuery string) (dTable *db.DataTable, err error) {
	req, err := requests.MakeRowRangeReqs(rawQuery)
	if err != nil {
		return nil, err
	}
	dTable, err = getDataTableRaw(D, req)
	if err != nil {
		return nil, err
	}

	regressParams, err := requests.MakeRegressionParams(rawQuery)
	if err != nil {
		return nil, err
	}
	if regressParams.Selected {
		// Regression detection needs an ascending time sort, so perform this first
		// when the X-axis is already time.
		dTable.SortRows(0)
		dTable.GetVerifiedRegression(regressParams)
	}

	timeSort := req.SortByColumn == common.TimeName
	if !timeSort {
		if err = dTable.ChangeXAxisToColumnFromTime(req.SortByColumn); err != nil {
			return nil, err
		}
	}

	// Sort only if we haven't already (because we didn't enable regression
	// detection) or need to because we've changed the X-axis.
	if !regressParams.Selected || !timeSort {
		dTable.SortRows(0)
	}

	if req.SortByConfig != "" {
		err = dTable.ChangeXAxisToConfigColumn(req.SortByConfig,
			dTable.Timestamps == nil) // Timestamps not saved.
		if err != nil {
			return nil, err
		}
		// Use slower stable sort to allow 2-level sort, most typically of the form:
		// <configKey>:<Time>
		dTable.SortRowsStable(0)
	}

	q, _ := url.ParseQuery(rawQuery)
	reverse := q.Get("reverse") == "1"
	if reverse {
		dTable.ReverseRows()
	}

	if req.EqualX { // Only perform after all sorting is done.
		tAddColumn := time.Now()
		if dTable.Timestamps != nil { // Timestamps already saved.
			dTable.OverwriteXAxisWithRecordNum()
		} else {
			dTable.ChangeXAxisToRecordNumFromTime()
		}
		glog.V(3).Infof("PERF: add recordNum column time: %v\n", time.Now().Sub(tAddColumn))
	}
	return dTable, nil
}