lastWrite time.Time // The last time we wrote a log entry
modified bool // Has this data been modified since the last write
+
+ editHooks []func(map[string]interface{},map[string]interface{})
}
// Create a new logger based on the specified parameters.
func (l *Logger) Edit() (properties map[string]interface{}, entry map[string]interface{}) {
l.lock.Lock()
l.modified = true // We don't actually know the caller will modifiy the data, but we assume they will.
+
+ // Run all our hooks
+ for _, hook := range l.editHooks {
+ hook(l.properties, l.entry)
+ }
+
return l.properties, l.entry
}
+// Adds a hook which will be called everytime Edit() is called.
+// The hook takes properties and entry as arguments, in that order.
+// This is useful for stuff like memory profiling.
+// This must be called between Edit() and Record().
+// For convenience AddEditHook will call hook when it is added as well.
+func (l *Logger) AddEditHook(hook func(map[string]interface{},
+ map[string]interface{})) {
+ l.editHooks = append(l.editHooks, hook)
+ hook(l.properties, l.entry)
+}
+
// Write the log entry you've built up so far. Do not edit the maps
// returned by Edit() after calling this method.
// If you have already written within MinimumWriteInterval, then this
properties,_ := params.Logger.Edit()
collectionInfo := properties["collection_info"].(map[string]interface{})
collectionInfo["collections_read"] = totalCollections
- collectionInfo["latest_modified_date"] = sdkParams["filters"].([][]string)[0][2]
+ collectionInfo["latest_modified_date_seen"] = sdkParams["filters"].([][]string)[0][2]
collectionInfo["total_manifest_size"] = totalManifestSize
collectionInfo["max_manifest_size"] = maxManifestSize
params.Logger.Record()
"git.curoverse.com/arvados.git/services/datamanager/keep"
"log"
"os"
+ "runtime"
"time"
)
}
runInfo["pid"] = os.Getpid()
properties["run_info"] = runInfo
+
+ arvLogger.AddEditHook(LogMemoryAlloc)
+
arvLogger.Record()
}
// This requires waiting on them to finish before you let main() exit.
RunCollections(collection.GetCollectionsParams{
- Client: arv, Logger: arvLogger, BatchSize: 500})
+ Client: arv, Logger: arvLogger, BatchSize: 100})
RunKeep(keep.GetKeepServersParams{Client: arv, Limit: 1000})
}
}
return
}
+
+func LogMemoryAlloc(properties map[string]interface{}, entry map[string]interface{}) {
+ _ = entry // keep the compiler from complaining
+ runInfo := properties["run_info"].(map[string]interface{})
+ var memStats runtime.MemStats
+ runtime.ReadMemStats(&memStats)
+ runInfo["alloc_bytes_in_use"] = memStats.Alloc
+}