x/ref: Restructure debug,logreader,pprof,repository,stats,vtrace.

services/mgmt/debug          -> services/debug/debuglib/dispatcher.go
services/mgmt/logreader/impl -> services/logreader/logreaderlib
services/mgmt/pprof/impl     -> services/pprof/pproflib
services/mgmt/pprof/client   -> services/pprof/pproflib
services/mgmt/repository     -> services/repository
services/mgmt/stats          -> services/stats
services/mgmt/stats/impl     -> services/stats/statslib
services/mgmt/vtrace/impl    -> services/vtrace/vtracelib

Change-Id: I3dadc6ff0c07330a16d6db281bf7ed034bc9c45f
diff --git a/services/vtrace/vtracelib/vtrace.go b/services/vtrace/vtracelib/vtrace.go
new file mode 100644
index 0000000..9291406
--- /dev/null
+++ b/services/vtrace/vtracelib/vtrace.go
@@ -0,0 +1,41 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package vtracelib
+
+import (
+	"v.io/v23/rpc"
+	s_vtrace "v.io/v23/services/vtrace"
+	"v.io/v23/uniqueid"
+	"v.io/v23/verror"
+	"v.io/v23/vtrace"
+)
+
+type vtraceService struct{}
+
+func (v *vtraceService) Trace(call rpc.ServerCall, id uniqueid.Id) (vtrace.TraceRecord, error) {
+	store := vtrace.GetStore(call.Context())
+	tr := store.TraceRecord(id)
+	if tr == nil {
+		return vtrace.TraceRecord{}, verror.New(verror.ErrNoExist, call.Context(), "No trace with id %x", id)
+	}
+	return *tr, nil
+}
+
+func (v *vtraceService) AllTraces(call s_vtrace.StoreAllTracesServerCall) error {
+	// TODO(mattr): Consider changing the store to allow us to iterate through traces
+	// when there are many.
+	store := vtrace.GetStore(call.Context())
+	traces := store.TraceRecords()
+	for i := range traces {
+		if err := call.SendStream().Send(traces[i]); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func NewVtraceService() interface{} {
+	return s_vtrace.StoreServer(&vtraceService{})
+}