VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CPUProfileImpl.cpp@ 86714

Last change on this file since 86714 was 85574, checked in by vboxsync, 4 years ago

Main: Added ISystemProperties::getCPUProfiles.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: CPUProfileImpl.cpp 85574 2020-07-31 12:45:16Z vboxsync $ */
2/** @file
3 * VirtualBox Main - interface for CPU profiles, VBoxSVC.
4 */
5
6/*
7 * Copyright (C) 2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include "CPUProfileImpl.h"
23
24#include <VBox/vmm/cpum.h>
25#include <iprt/x86.h>
26#include "AutoCaller.h"
27
28
29DEFINE_EMPTY_CTOR_DTOR(CPUProfile)
30
31/**
32 * Called by ComObjPtr::createObject when creating the object.
33 *
34 * Just initialize the basic object state, do the rest in initFromDbEntry().
35 *
36 * @returns S_OK.
37 */
38HRESULT CPUProfile::FinalConstruct()
39{
40 m_enmArchitecture = CPUArchitecture_Any;
41 return BaseFinalConstruct();
42}
43
44/**
45 * Initializes the CPU profile from the given CPUM CPU database entry.
46 *
47 * @returns COM status code.
48 * @param a_pDbEntry The CPU database entry.
49 */
50HRESULT CPUProfile::initFromDbEntry(PCCPUMDBENTRY a_pDbEntry) RT_NOEXCEPT
51{
52 AutoInitSpan autoInitSpan(this);
53 AssertReturn(autoInitSpan.isOk(), E_FAIL);
54
55 /*
56 * Initialize our private data.
57 */
58
59 /* Determin x86 or AMD64 by scanning the CPUID leaves for the long mode feature bit: */
60 m_enmArchitecture = CPUArchitecture_x86;
61 uint32_t iLeaf = a_pDbEntry->cCpuIdLeaves;
62 while (iLeaf-- > 0)
63 if (a_pDbEntry->paCpuIdLeaves[iLeaf].uLeaf <= UINT32_C(0x80000001))
64 {
65 if ( a_pDbEntry->paCpuIdLeaves[iLeaf].uLeaf == UINT32_C(0x80000001)
66 && (a_pDbEntry->paCpuIdLeaves[iLeaf].uEdx & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE))
67 m_enmArchitecture = CPUArchitecture_AMD64;
68 break;
69 }
70
71 HRESULT hrc = m_strName.assignEx(a_pDbEntry->pszName);
72 if (SUCCEEDED(hrc))
73 hrc = m_strFullName.assignEx(a_pDbEntry->pszFullName);
74
75 /*
76 * Update the object state.
77 */
78 if (SUCCEEDED(hrc))
79 autoInitSpan.setSucceeded();
80 else
81 autoInitSpan.setFailed(hrc);
82 return hrc;
83}
84
85/**
86 * COM cruft.
87 */
88void CPUProfile::FinalRelease()
89{
90 uninit();
91 BaseFinalRelease();
92}
93
94/**
95 * Do the actual cleanup.
96 */
97void CPUProfile::uninit()
98{
99 AutoUninitSpan autoUninitSpan(this);
100}
101
102/**
103 * Used by SystemProperties::getCPUProfiles to do matching.
104 */
105bool CPUProfile::i_match(CPUArchitecture_T a_enmArchitecture, CPUArchitecture_T a_enmSecondaryArch,
106 const com::Utf8Str &a_strNamePattern) const RT_NOEXCEPT
107{
108 if ( m_enmArchitecture == a_enmArchitecture
109 || m_enmArchitecture == a_enmSecondaryArch)
110 {
111 if (a_strNamePattern.isEmpty())
112 return true;
113 return RTStrSimplePatternMatch(a_strNamePattern.c_str(), m_strName.c_str());
114 }
115 return false;
116}
117
118
119HRESULT CPUProfile::getName(com::Utf8Str &aName)
120{
121 return aName.assignEx(m_strName);
122}
123
124HRESULT CPUProfile::getFullName(com::Utf8Str &aFullName)
125{
126 return aFullName.assignEx(m_strFullName);
127}
128
129HRESULT CPUProfile::getArchitecture(CPUArchitecture_T *aArchitecture)
130{
131 *aArchitecture = m_enmArchitecture;
132 return S_OK;
133}
134
135
136/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette