blob: 9d13d5a08453a44396249813a2190fb1a4209a69 [file] [log] [blame]
Stephane Barbarieec0919b2018-09-05 14:14:29 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package model
17
18import (
19 "sync"
20 "github.com/opencord/voltha-go/common/log"
21)
22
23type profiling struct {
24 DatabaseRetrieveTime float64
25 DatabaseRetrieveCount int
26 InMemoryModelTime float64
27 InMemoryModelCount int
28 InMemoryProcessTime float64
29 DatabaseStoreTime float64
30}
31
32var profiling_instance *profiling
33var profiling_once sync.Once
34
35func GetProfiling() *profiling {
36 profiling_once.Do(func() {
37 profiling_instance = &profiling{}
38 })
39 return profiling_instance
40}
41
42func (p *profiling) AddToDatabaseRetrieveTime(period float64) {
43 p.DatabaseRetrieveTime += period
44 p.DatabaseRetrieveCount += 1
45}
46func (p *profiling) AddToInMemoryModelTime(period float64) {
47 p.InMemoryModelTime += period
48 p.InMemoryModelCount += 1
49}
50func (p *profiling) AddToInMemoryProcessTime(period float64) {
51 p.InMemoryProcessTime += period
52}
53func (p *profiling) AddToDatabaseStoreTime(period float64) {
54 p.DatabaseStoreTime += period
55}
56
57func (p *profiling) Report() {
58 log.Infof("[ Profiling Report ]")
59 log.Infof("Database Retrieval : %f", p.DatabaseRetrieveTime)
60 log.Infof("Database Retrieval Count : %d", p.DatabaseRetrieveCount)
61 log.Infof("Avg Database Retrieval : %f", p.DatabaseRetrieveTime/float64(p.DatabaseRetrieveCount))
62 log.Infof("In-Memory Modeling : %f", p.InMemoryModelTime)
63 log.Infof("In-Memory Modeling Count: %d", p.InMemoryModelCount)
64 log.Infof("Avg In-Memory Modeling : %f", p.InMemoryModelTime/float64(p.InMemoryModelCount))
65
66}