add debug option, estimate performance of /recall

pull/30/head
Simon Let 6 years ago
parent 3701a9c8cf
commit 4faf1a8832
  1. 4
      cmd/daemon/main.go
  2. 10
      cmd/daemon/recall.go
  3. 4
      cmd/daemon/run-server.go
  4. 1
      conf/config.toml
  5. 1
      pkg/cfg/cfg.go
  6. 11
      pkg/sesshist/sesshist.go

@ -48,6 +48,10 @@ func main() {
log.Println("Error reading config", err)
return
}
if config.Debug {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
}
res, err := isDaemonRunning(config.Port)
if err != nil {
log.Println("Error while checking if the daemon is runnnig", err)

@ -16,6 +16,8 @@ type recallHandler struct {
}
func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println("/recall START")
log.Println("/recall reading body ...")
jsn, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Println("Error reading the body", err)
@ -23,19 +25,22 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
rec := records.Record{}
log.Println("/recall unmarshaling record ...")
err = json.Unmarshal(jsn, &rec)
if err != nil {
log.Println("Decoding error:", err)
log.Println("Payload:", jsn)
return
}
log.Println("/recall recalling ...")
cmd, err := h.sesshistDispatch.Recall(rec.SessionID, rec.RecallHistno, rec.RecallPrefix)
if err != nil {
log.Println("/recall - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ERROR")
log.Println("Recall error:", err)
return
}
resp := collect.SingleResponse{cmd}
resp := collect.SingleResponse{CmdLine: cmd}
log.Println("/recall marshaling response ...")
jsn, err = json.Marshal(&resp)
if err != nil {
log.Println("Encoding error:", err)
@ -43,6 +48,7 @@ func (h *recallHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
log.Println(string(jsn))
log.Println("/recall writing response ...")
w.Write(jsn)
log.Println("/recall - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ", cmd)
log.Println("/recall END - sess id:", rec.SessionID, " - histno:", rec.RecallHistno, " -> ", cmd)
}

@ -39,7 +39,9 @@ func runServer(config cfg.Config, historyPath string) {
histfileBox := histfile.New(histfileRecords, historyPath, 10000, histfileSessionsToDrop, histfileSignals, shutdown)
// sesshist New
sesshistDispatch := sesshist.NewDispatch(sesshistSessionsToInit, sesshistSessionsToDrop, sesshistRecords, histfileBox, config.SesshistInitHistorySize)
sesshistDispatch := sesshist.NewDispatch(sesshistSessionsToInit, sesshistSessionsToDrop,
sesshistRecords, histfileBox,
config.SesshistInitHistorySize)
// sesswatch
sesswatchSessionsToWatch := make(chan records.Record)

@ -1,3 +1,4 @@
port = 2627
sesswatchPeriodSeconds = 120
sesshistInitHistorySize = 1000
debug = true

@ -5,4 +5,5 @@ type Config struct {
Port int
SesswatchPeriodSeconds uint
SesshistInitHistorySize int
Debug bool
}

@ -133,7 +133,9 @@ func (s *Dispatch) addRecentRecord(sessionID string, record records.Record) erro
// Recall command from recent session history
func (s *Dispatch) Recall(sessionID string, histno int, prefix string) (string, error) {
log.Println("sesshist - recall: RLocking main lock ...")
s.mutex.RLock()
log.Println("sesshist - recall: Getting session history struct ...")
session, found := s.sessions[sessionID]
s.mutex.RUnlock()
@ -141,13 +143,14 @@ func (s *Dispatch) Recall(sessionID string, histno int, prefix string) (string,
// go s.initSession(sessionID)
return "", errors.New("sesshist ERROR: No session history for SessionID " + sessionID + " - should we create one?")
}
log.Println("sesshist - recall: Locking session lock ...")
session.mutex.Lock()
defer session.mutex.Unlock()
if prefix == "" {
session.mutex.Lock()
defer session.mutex.Unlock()
log.Println("sesshist - recall: Getting records by histno ...")
return session.getRecordByHistno(histno)
}
session.mutex.Lock()
defer session.mutex.Unlock()
log.Println("sesshist - recall: Searching for records by prefix ...")
return session.searchRecordByPrefix(prefix, histno)
}

Loading…
Cancel
Save