File: cm_ftrace.cpp

package info (click to toggle)
intel-media-driver 21.1.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,772 kB
  • sloc: cpp: 1,078,942; ansic: 164,231; asm: 45,336; python: 554; sh: 177; makefile: 13
file content (125 lines) | stat: -rw-r--r-- 4,342 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2007-2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file      cm_ftrace.cpp
//! \brief     Class Cm Ftrace definitions
//!

#include "cm_ftrace.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include "cm_task_internal.h"

#define TRACE_MARKER_PATH "/sys/kernel/debug/tracing/trace_marker"

#define TRACE_FLAG_PATH "/sys/kernel/debug/tracing/tracing_on"

#define MSG_LENGTH 1024

#define PRINT_TO_STRING(_fmt, _value)    \
    byteInput = snprintf(msgBuf + byteOffset, MSG_LENGTH - byteOffset, _fmt, _value); \
    byteOffset += byteInput;

//Global static pointer to ensure a single instance
CmFtrace* CmFtrace::m_ftrace = nullptr;

CmFtrace::CmFtrace()
{
    m_filehandle = open( TRACE_MARKER_PATH, O_WRONLY );
}

CmFtrace::~CmFtrace()
{
    if(m_filehandle >= 0)
    {
        close(m_filehandle);
    }
}

CmFtrace* CmFtrace::GetInstance()
{
    if(m_ftrace == nullptr)
    {
        m_ftrace = new (std::nothrow) CmFtrace();
    }

    return m_ftrace;
}

void CmFtrace::WriteTaskProfilingInfo(CM_PROFILING_INFO *taskInfo)
{
    if(taskInfo == nullptr)
    {
        return ;
    }

    char msgBuf[MSG_LENGTH];
    uint byteOffset = 0;
    uint byteInput = 0;

    PRINT_TO_STRING("%s: ", "mdf_v1")
    PRINT_TO_STRING("kernelcount=%d|", taskInfo->kernelCount);
    PRINT_TO_STRING("taskid=%d|",      taskInfo->taskID);
    PRINT_TO_STRING("threadid=%u|",    taskInfo->threadID);

    uint kernelNameOffset = 0;
    for(uint i=0 ; i< taskInfo->kernelCount; i++)
    {
        //Kernel name.
        char *kernelname = taskInfo->kernelNames + kernelNameOffset;
        PRINT_TO_STRING("kernelname=%s|", kernelname);
        kernelNameOffset += strlen(kernelname) + 1;

        //Local work width&height
        PRINT_TO_STRING("localwidth=%d|", taskInfo->localWorkWidth[i]);
        PRINT_TO_STRING("localheight=%d|", taskInfo->localWorkHeight[i]);

        //Global work width&height
        PRINT_TO_STRING("globalwidth=%d|",  taskInfo->globalWorkWidth[i]);
        PRINT_TO_STRING("globalheight=%d|", taskInfo->globalWorkHeight[i]);
    }

    //Note: enqueuetime/flushtime/completetime are measured in performance counter
    //Don't need to convert to nanosec on Linux since MOS_QueryPerformanceFrequency returns 1
    //On linux, we can't get the gpu ticks when the command submitted, so that
    //we can't do the adjustment the ticks b/w cpu and gpu, as what we did on windoes by GetGpuTime
    //hw_start_time = flush_time; hw_end_time = hw_start_time + kernel_execution_time

    LARGE_INTEGER kernelExeTime;
    kernelExeTime.QuadPart = taskInfo->hwEndTime.QuadPart - taskInfo->hwStartTime.QuadPart;

    //write time stampes
    PRINT_TO_STRING("enqueuetime=%lld|",   (long long)taskInfo->enqueueTime.QuadPart);
    PRINT_TO_STRING("flushtime=%lld|",     (long long)taskInfo->flushTime.QuadPart);
    PRINT_TO_STRING("hwstarttime=%lld|",   (long long)taskInfo->flushTime.QuadPart);
    PRINT_TO_STRING("hwendtime=%lld|",     (long long)(taskInfo->flushTime.QuadPart + kernelExeTime.QuadPart) );
    PRINT_TO_STRING("completetime=%lld\n", (long long)taskInfo->completeTime.QuadPart);

    // write message to trace_marker
    size_t writeSize = write(m_filehandle, msgBuf, byteOffset);

    return;
}