本文整理汇总了Golang中go/skia/org/infra/go/timer.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: update
// update syncs the source code repository and loads any new commits.
func (c *CommitCache) update() (rv error) {
defer timer.New("CommitCache.update()").Stop()
glog.Info("Reloading commits.")
if err := c.repo.Update(true, true); err != nil {
return fmt.Errorf("Failed to update the repo: %v", err)
}
from := time.Time{}
n := c.NumCommits()
if n > 0 {
last, err := c.Get(n - 1)
if err != nil {
return fmt.Errorf("Failed to get last commit: %v", err)
}
from = last.Timestamp
}
newCommitHashes := c.repo.From(from)
glog.Infof("Processing %d new commits.", len(newCommitHashes))
newCommits := make([]*gitinfo.LongCommit, len(newCommitHashes))
if len(newCommitHashes) > 0 {
for i, h := range newCommitHashes {
d, err := c.repo.Details(h)
if err != nil {
return fmt.Errorf("Failed to obtain commit details for %s: %v", h, err)
}
newCommits[i] = d
}
}
branchHeads, err := c.repo.GetBranches()
if err != nil {
return fmt.Errorf("Failed to read branch information from the repo: %v", err)
}
// Load new builds for the BuildCache.
allCommits := append(c.Commits, newCommits...)
buildCacheHashes := make([]string, 0, c.requestSize)
for _, commit := range allCommits[len(allCommits)-c.requestSize:] {
buildCacheHashes = append(buildCacheHashes, commit.Hash)
}
byId, byCommit, builderStatuses, err := build_cache.LoadData(buildCacheHashes)
if err != nil {
return fmt.Errorf("Failed to update BuildCache: %v", err)
}
// Update the cached values all at once at at the end.
glog.Infof("Updating the cache.")
// Write the cache to disk *after* unlocking it.
defer func() {
rv = c.toFile()
}()
defer timer.New(" CommitCache locked").Stop()
c.mutex.Lock()
defer c.mutex.Unlock()
c.BranchHeads = branchHeads
c.Commits = allCommits
c.buildCache.UpdateWithData(byId, byCommit, builderStatuses)
glog.Infof("Finished updating the cache.")
return nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:59,代码来源:commit_cache.go
示例2: RemoveChange
// RemoveChange, see ExpectationsStore interface.
func (s *SQLExpectationsStore) RemoveChange(changedDigests map[string][]string) (retErr error) {
defer timer.New("removing exp change").Stop()
const markRemovedStmt = `UPDATE exp_test_change
SET removed = IF(removed IS NULL, ?, removed)
WHERE (name=?) AND (digest=?)`
// start a transaction
tx, err := s.vdb.DB.Begin()
if err != nil {
return err
}
defer func() { retErr = database.CommitOrRollback(tx, retErr) }()
// Mark all the digests as removed.
now := util.TimeStampMs()
for testName, digests := range changedDigests {
for _, digest := range digests {
if _, err = tx.Exec(markRemovedStmt, now, testName, digest); err != nil {
return err
}
}
}
return nil
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:28,代码来源:sqlexpstore.go
示例3: addBuildCommentHandler
func addBuildCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("addBuildCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
cache, err := getCommitCache(w, r)
if err != nil {
return
}
buildId, err := strconv.ParseInt(mux.Vars(r)["buildId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid build id: %v", err))
return
}
comment := struct {
Comment string `json:"comment"`
}{}
if err := json.NewDecoder(r.Body).Decode(&comment); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
defer util.Close(r.Body)
c := buildbot.BuildComment{
BuildId: int(buildId),
User: login.LoggedInAs(r),
Timestamp: float64(time.Now().UTC().Unix()),
Message: comment.Comment,
}
if err := cache.AddBuildComment(int(buildId), &c); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:35,代码来源:main.go
示例4: deleteBuildCommentHandler
func deleteBuildCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("deleteBuildCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
cache, err := getCommitCache(w, r)
if err != nil {
return
}
buildId, err := strconv.ParseInt(mux.Vars(r)["buildId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid build id: %v", err))
return
}
commentId, err := strconv.ParseInt(mux.Vars(r)["commentId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid comment id: %v", err))
return
}
if err := cache.DeleteBuildComment(int(buildId), int(commentId)); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to delete comment: %v", err))
return
}
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:26,代码来源:main.go
示例5: addCommitCommentHandler
func addCommitCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("addCommitCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
commit := mux.Vars(r)["commit"]
comment := struct {
Comment string `json:"comment"`
}{}
if err := json.NewDecoder(r.Body).Decode(&comment); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
defer util.Close(r.Body)
c := buildbot.CommitComment{
Commit: commit,
User: login.LoggedInAs(r),
Timestamp: time.Now().UTC(),
Message: comment.Comment,
}
if err := db.PutCommitComment(&c); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add commit comment: %v", err))
return
}
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:28,代码来源:main.go
示例6: getCandidatesForBuilder
// getCandidatesForBuilder finds all BuildCandidates for the given builder, in order.
func (q *BuildQueue) getCandidatesForBuilder(bf *buildFinder, recentCommits []string, now time.Time) ([]*BuildCandidate, error) {
defer timer.New(fmt.Sprintf("getCandidatesForBuilder(%s)", bf.Builder)).Stop()
repo, err := q.repos.Repo(bf.Repo)
if err != nil {
return nil, err
}
candidates := []*BuildCandidate{}
for {
score, newBuild, stoleFrom, err := q.getBestCandidate(bf, recentCommits, now)
if err != nil {
return nil, fmt.Errorf("Failed to get build candidates for %s: %v", bf.Builder, err)
}
if score < q.scoreThreshold {
break
}
d, err := repo.Details(newBuild.GotRevision)
if err != nil {
return nil, err
}
// "insert" the new build.
bf.add(newBuild)
if stoleFrom != nil {
bf.add(stoleFrom)
}
candidates = append(candidates, &BuildCandidate{
Author: d.Author,
Builder: newBuild.Builder,
Commit: newBuild.GotRevision,
Score: score,
Repo: bf.Repo,
})
}
return candidates, nil
}
开发者ID:Tiger66639,项目名称:skia-buildbot,代码行数:35,代码来源:build_queue.go
示例7: New
// New creates and returns a new CommitCache which watches the given repo.
// The initial update will load ALL commits from the repository, so expect
// this to be slow.
func New(repo *gitinfo.GitInfo, cacheFile string, requestSize int) (*CommitCache, error) {
defer timer.New("commit_cache.New()").Stop()
c, err := fromFile(cacheFile)
if err != nil {
glog.Warningf("Failed to read commit cache from file; starting from scratch. Error: %v", err)
c = &CommitCache{}
}
c.buildCache = &build_cache.BuildCache{}
c.cacheFile = cacheFile
c.repo = repo
c.requestSize = requestSize
// Update the cache.
if err := c.update(); err != nil {
return nil, err
}
// Update in a loop.
go func() {
for _ = range time.Tick(time.Minute) {
if err := c.update(); err != nil {
glog.Errorf("Failed to update commit cache: %v", err)
}
}
}()
return c, nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:30,代码来源:commit_cache.go
示例8: LoadData
// LoadData loads the build data for the given commits.
func LoadData(commits []string) (map[int]*buildbot.Build, map[string]map[string]*buildbot.BuildSummary, map[string][]*buildbot.BuilderComment, error) {
defer timer.New("build_cache.LoadData()").Stop()
builds, err := buildbot.GetBuildsForCommits(commits, nil)
if err != nil {
return nil, nil, nil, err
}
byId := map[int]*buildbot.Build{}
byCommit := map[string]map[string]*buildbot.BuildSummary{}
builders := map[string]bool{}
for hash, buildList := range builds {
byBuilder := map[string]*buildbot.BuildSummary{}
for _, b := range buildList {
byId[b.Id] = b
if !util.AnyMatch(BOT_BLACKLIST, b.Builder) {
byBuilder[b.Builder] = b.GetSummary()
builders[b.Builder] = true
}
}
byCommit[hash] = byBuilder
}
builderList := make([]string, 0, len(builders))
for b, _ := range builders {
builderList = append(builderList, b)
}
builderComments, err := buildbot.GetBuildersComments(builderList)
if err != nil {
return nil, nil, nil, err
}
return byId, byCommit, builderComments, nil
}
开发者ID:Tiger66639,项目名称:skia-buildbot,代码行数:31,代码来源:build_cache.go
示例9: Run
// Run executes the function for the given test and returns an error if it fails.
func (t test) Run() error {
defer timer.New(t.Name).Stop()
err, output := t.run()
if err != nil {
return fmt.Errorf(TEST_FAILURE, t.Name, t.Cmd, err, output)
}
return nil
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:9,代码来源:run_unittests.go
示例10: UpdateWithData
// UpdateWithData replaces the contents of the BuildCache with the given
// data. Not intended to be used by consumers of BuildCache, but exists to
// allow for loading and storing the cache data separately so that the cache
// may be locked for the minimum amount of time.
func (c *BuildCache) UpdateWithData(byId map[int]*buildbot.Build, byCommit map[string]map[string]*buildbot.BuildSummary, builders map[string][]*buildbot.BuilderComment) {
defer timer.New(" BuildCache locked").Stop()
c.mutex.Lock()
defer c.mutex.Unlock()
c.byId = byId
c.byCommit = byCommit
c.builders = builders
}
开发者ID:Tiger66639,项目名称:skia-buildbot,代码行数:12,代码来源:build_cache.go
示例11: toFile
// toFile saves the CommitCache to a file.
func (c *CommitCache) toFile() error {
defer timer.New("commit_cache.toFile()").Stop()
f, err := os.Create(c.cacheFile)
if err != nil {
return err
}
defer util.Close(f)
if err := gob.NewEncoder(f).Encode(c); err != nil {
return err
}
return nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:13,代码来源:commit_cache.go
示例12: infraHandler
func infraHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("infraHandler").Stop()
w.Header().Set("Content-Type", "text/html")
// Don't use cached templates in testing mode.
if *testing {
reloadTemplates()
}
if err := infraTemplate.Execute(w, struct{}{}); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to expand template: %v", err))
}
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:13,代码来源:main.go
示例13: hostsHandler
func hostsHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("hostsHandler").Stop()
w.Header().Set("Content-Type", "text/html")
// Don't use cached templates in testing mode.
if *testing {
reloadTemplates()
}
if err := hostsTemplate.Execute(w, struct{}{}); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:13,代码来源:main.go
示例14: fromFile
// fromFile attempts to load the CommitCache from the given file.
func fromFile(cacheFile string) (*CommitCache, error) {
defer timer.New("commit_cache.fromFile()").Stop()
c := CommitCache{}
if _, err := os.Stat(cacheFile); err != nil {
return nil, fmt.Errorf("Could not stat cache file: %v", err)
}
f, err := os.Open(cacheFile)
if err != nil {
return nil, fmt.Errorf("Failed to open cache file %s: %v", cacheFile, err)
}
defer util.Close(f)
if err := gob.NewDecoder(f).Decode(&c); err != nil {
return nil, fmt.Errorf("Failed to read cache file %s: %v", cacheFile, err)
}
return &c, nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:17,代码来源:commit_cache.go
示例15: GetBuildsFromDateRange
// GetBuildsFromDateRange retrieves all builds which finished in the given date range.
func GetBuildsFromDateRange(start, end time.Time) ([]*Build, error) {
defer timer.New("GetBuildsFromDateRange").Stop()
var ids []int
if err := DB.Select(&ids, fmt.Sprintf("SELECT id FROM %s WHERE started > ? and started < ?", TABLE_BUILDS), float64(start.UTC().Unix()), float64(end.UTC().Unix())); err != nil {
return nil, fmt.Errorf("Failed to obtain builds from date range: %v", err)
}
builds, err := GetBuildsFromDB(ids)
if err != nil {
return nil, err
}
rv := make([]*Build, 0, len(builds))
for _, b := range builds {
rv = append(rv, b)
}
return rv, nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:17,代码来源:db.go
示例16: oneStep
// oneStep does a single step, calculating all the paramsets from the latest tile and tallies.
//
// Returns the paramsets for both the tile with and without ignored traces included.
func oneStep(tallies *tally.Tallies, storages *storage.Storage) (map[string]map[string][]string, map[string]map[string][]string, error) {
defer timer.New("paramsets").Stop()
tile, err := storages.GetLastTileTrimmed(false)
if err != nil {
return nil, nil, fmt.Errorf("Failed to get tile: %s", err)
}
byTrace := byTraceForTile(tile, tallies.ByTrace())
tile, err = storages.GetLastTileTrimmed(true)
if err != nil {
return nil, nil, fmt.Errorf("Failed to get tile: %s", err)
}
byTraceIncludeIgnored := byTraceForTile(tile, tallies.ByTrace())
return byTrace, byTraceIncludeIgnored, nil
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:20,代码来源:paramsets.go
示例17: LoggingGzipRequestResponse
// LoggingGzipRequestResponse records parts of the request and the response to the logs.
func LoggingGzipRequestResponse(h http.Handler) http.Handler {
// Closure to capture the request.
f := func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
glog.Errorf("panic serving %v: %v\n%s", r.URL.Path, err, buf)
}
}()
defer timer.New(fmt.Sprintf("Request: %s %s %#v Content Length: %d Latency:", r.URL.Path, r.Method, r.URL, r.ContentLength)).Stop()
h.ServeHTTP(w, r)
}
return autogzip.Handle(recordResponse(http.HandlerFunc(f)))
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:18,代码来源:http.go
示例18: newHistorian
// Create a new instance of historian.
func newHistorian(storages *storage.Storage, nTilesToBackfill int) (*historian, error) {
defer timer.New("historian").Stop()
ret := &historian{
storages: storages,
}
// Start running the background process to gather digestinfo.
if err := ret.start(); err != nil {
return nil, err
}
// There is at least one tile to backfill digestinfo then start the process.
if nTilesToBackfill > 0 {
ret.backFillDigestInfo(nTilesToBackfill)
}
return ret, nil
}
开发者ID:kleopatra999,项目名称:skia-buildbot,代码行数:20,代码来源:history.go
示例19: commitsJsonHandler
func commitsJsonHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("commitsJsonHandler").Stop()
w.Header().Set("Content-Type", "application/json")
cache, err := getCommitCache(w, r)
if err != nil {
return
}
commitsToLoad := DEFAULT_COMMITS_TO_LOAD
n, err := getIntParam("n", r)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid parameter: %v", err))
return
}
if n != nil {
commitsToLoad = *n
}
if err := cache.LastNAsJson(w, commitsToLoad); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to load commits from cache: %v", err))
return
}
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:21,代码来源:main.go
示例20: update
// update is the inner function which does all the work for Update. It accepts
// a time.Time so that time.Now() can be faked for testing.
func (q *BuildQueue) update(now time.Time) error {
glog.Info("Updating build queue.")
defer timer.New("BuildQueue.update()").Stop()
queue := map[string][]*BuildCandidate{}
errs := map[string]error{}
mutex := sync.Mutex{}
var wg sync.WaitGroup
for _, repoUrl := range q.repos.Repos() {
wg.Add(1)
go func(repoUrl string) {
defer wg.Done()
candidates, err := q.updateRepo(repoUrl, now)
mutex.Lock()
defer mutex.Unlock()
if err != nil {
errs[repoUrl] = err
return
}
for k, v := range candidates {
queue[k] = v
}
}(repoUrl)
}
wg.Wait()
if len(errs) > 0 {
msg := "Failed to update repos:"
for repoUrl, err := range errs {
msg += fmt.Sprintf("\n%s: %v", repoUrl, err)
}
return fmt.Errorf(msg)
}
// Update the queues.
q.lock.Lock()
defer q.lock.Unlock()
q.queue = queue
return nil
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:41,代码来源:build_queue.go
注:本文中的go/skia/org/infra/go/timer.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论