aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/PeriodicCounterSelectionCommandHandler.cpp
blob: 9be37fcfd2554a6cd89eef01bf7b9f8af3b2a1ba (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
//
// Copyright © 2019 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "PeriodicCounterSelectionCommandHandler.hpp"
#include "ProfilingUtils.hpp"

#include <boost/numeric/conversion/cast.hpp>

namespace armnn
{

namespace profiling
{

using namespace std;
using boost::numeric_cast;

void PeriodicCounterSelectionCommandHandler::ParseData(const Packet& packet, CaptureData& captureData)
{
    std::vector<uint16_t> counterIds;
    uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
    uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
    uint32_t offset = 0;

    if (packet.GetLength() > 0)
    {
        if (packet.GetLength() >= 4)
        {
            captureData.SetCapturePeriod(ReadUint32(reinterpret_cast<const unsigned char*>(packet.GetData()), offset));

            unsigned int counters = (packet.GetLength() - 4) / 2;

            if (counters > 0)
            {
                counterIds.reserve(counters);
                offset += sizeOfUint32;
                for(unsigned int pos = 0; pos < counters; ++pos)
                {
                    counterIds.emplace_back(ReadUint16(reinterpret_cast<const unsigned char*>(packet.GetData()),
                                            offset));
                    offset += sizeOfUint16;
                }
            }

            captureData.SetCounterIds(counterIds);
        }
    }
}

void PeriodicCounterSelectionCommandHandler::operator()(const Packet& packet)
{
    CaptureData captureData;

    ParseData(packet, captureData);

    vector<uint16_t> counterIds = captureData.GetCounterIds();

    m_CaptureDataHolder.SetCaptureData(captureData.GetCapturePeriod(), counterIds);

    m_CaptureThread.Start();

    // Write packet to Counter Stream Buffer
    m_SendCounterPacket.SendPeriodicCounterSelectionPacket(captureData.GetCapturePeriod(), captureData.GetCounterIds());
}

} // namespace profiling

} // namespace armnn