summaryrefslogtreecommitdiff
path: root/perfstatsd/include/perfstats_buffer.h
blob: 3115c8b431b49c114d7d2ffb13a84ad78771cfbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _PERFSTATS_BUFFER_H_
#define _PERFSTATS_BUFFER_H_

#include <dirent.h>
#include <inttypes.h>
#include <pthread.h>
#include <time.h>

#include <chrono>
#include <iomanip>
#include <list>
#include <memory>
#include <mutex>
#include <queue>
#include <regex>
#include <sstream>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>

#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
#include <utils/RefBase.h>

namespace android {
namespace pixel {
namespace perfstatsd {

constexpr auto operator""_KiB(unsigned long long const num) {
    return num * 1024;
}

class StatsData {
  public:
    std::chrono::system_clock::time_point getTime() const { return mTime; }
    std::string getData() const { return mData; }
    void setTime(std::chrono::system_clock::time_point &time) { mTime = time; }
    void setData(std::string &data) { mData = data; }

  private:
    std::chrono::system_clock::time_point mTime;
    std::string mData;
};

class PerfstatsBuffer {
  public:
    size_t size() { return mBufferSize; }
    size_t count() { return mStorage.size(); }

    void setSize(size_t size) { mBufferSize = size; }
    void emplace(StatsData &&data);
    const std::queue<StatsData> &dump(void);

  private:
    size_t mBufferSize = 0U;
    std::queue<StatsData> mStorage;
};

struct StatsdataCompare {
    // sort time in ascending order
    bool operator()(const StatsData &a, const StatsData &b) const {
        return a.getTime() > b.getTime();
    }
};

}  // namespace perfstatsd
}  // namespace pixel
}  // namespace android

#endif /*  _PERFSTATS_BUFFER_H_ */