1 /*
2  *     Copyright 2014 Couchbase, Inc.
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  */
16 
17 #ifndef SRC_TASKLOGENTRY_H_
18 #define SRC_TASKLOGENTRY_H_ 1
19 
20 #include "config.h"
21 
22 #include <deque>
23 #include <list>
24 #include <map>
25 #include <queue>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 #include "task_type.h"
30 
31 /**
32  * Log entry for previous job runs.
33  */
34 class TaskLogEntry {
35 public:
36 
37     // This is useful for the ringbuffer to initialize
TaskLogEntry()38     TaskLogEntry() : name("invalid"), duration(0) {}
TaskLogEntry(const std::string &n, task_type_t type, const hrtime_t d, rel_time_t t = 0)39     TaskLogEntry(const std::string &n, task_type_t type, const hrtime_t d,
40                  rel_time_t t = 0)
41         : name(n), taskType(type), ts(t), duration(d) {}
42 
43     /**
44      * Get the name of the job.
45      */
getName() const46     std::string getName() const { return name; }
47 
48     /**
49      * Get the type of the task (Writer, Reader, AuxIO, NonIO)
50      */
getTaskType() const51      task_type_t getTaskType() const { return taskType; }
52 
53     /**
54      * Get the amount of time (in microseconds) this job ran.
55      */
getDuration() const56     hrtime_t getDuration() const { return duration; }
57 
58     /**
59      * Get a timestamp indicating when this thing started.
60      */
getTimestamp() const61     rel_time_t getTimestamp() const { return ts; }
62 
63 private:
64     std::string name;
65     task_type_t taskType;
66     rel_time_t ts;
67     hrtime_t duration;
68 };
69 
70 #endif  // SRC_TASKLOGENTRY_H_
71