VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp@ 72919

Last change on this file since 72919 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: PerformanceFreeBSD.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * VirtualBox Performance Collector, FreeBSD Specialization.
4 */
5
6/*
7 * Copyright (C) 2008-2017 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#include <sys/types.h>
19#include <sys/sysctl.h>
20#include "Performance.h"
21
22namespace pm {
23
24class CollectorFreeBSD : public CollectorHAL
25{
26public:
27 virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
28 virtual int getHostCpuMHz(ULONG *mhz);
29 virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
30 virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
31 virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
32};
33
34
35CollectorHAL *createHAL()
36{
37 return new CollectorFreeBSD();
38}
39
40int CollectorFreeBSD::getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle)
41{
42 return VERR_NOT_IMPLEMENTED;
43}
44
45int CollectorFreeBSD::getHostCpuMHz(ULONG *mhz)
46{
47 int CpuMHz = 0;
48 size_t cbParameter = sizeof(CpuMHz);
49
50 /** @todo Howto support more than one CPU? */
51 if (sysctlbyname("dev.cpu.0.freq", &CpuMHz, &cbParameter, NULL, 0))
52 return VERR_NOT_SUPPORTED;
53
54 *mhz = CpuMHz;
55
56 return VINF_SUCCESS;
57}
58
59int CollectorFreeBSD::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
60{
61 int rc = VINF_SUCCESS;
62 u_long cbMemPhys = 0;
63 u_int cPagesMemFree = 0;
64 u_int cPagesMemInactive = 0;
65 u_int cPagesMemCached = 0;
66 u_int cPagesMemUsed = 0;
67 int cbPage = 0;
68 size_t cbParameter = sizeof(cbMemPhys);
69 int cProcessed = 0;
70
71 if (!sysctlbyname("hw.physmem", &cbMemPhys, &cbParameter, NULL, 0))
72 cProcessed++;
73
74 cbParameter = sizeof(cPagesMemFree);
75 if (!sysctlbyname("vm.stats.vm.v_free_count", &cPagesMemFree, &cbParameter, NULL, 0))
76 cProcessed++;
77 cbParameter = sizeof(cPagesMemUsed);
78 if (!sysctlbyname("vm.stats.vm.v_active_count", &cPagesMemUsed, &cbParameter, NULL, 0))
79 cProcessed++;
80 cbParameter = sizeof(cPagesMemInactive);
81 if (!sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
82 cProcessed++;
83 cbParameter = sizeof(cPagesMemCached);
84 if (!sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
85 cProcessed++;
86 cbParameter = sizeof(cbPage);
87 if (!sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
88 cProcessed++;
89
90 if (cProcessed == 6)
91 {
92 *total = cbMemPhys / _1K;
93 *used = cPagesMemUsed * (cbPage / _1K);
94 *available = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * (cbPage / _1K);
95 }
96 else
97 rc = VERR_NOT_SUPPORTED;
98
99 return rc;
100}
101
102int CollectorFreeBSD::getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel)
103{
104 return VERR_NOT_IMPLEMENTED;
105}
106
107int CollectorFreeBSD::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
108{
109 return VERR_NOT_IMPLEMENTED;
110}
111
112int getDiskListByFs(const char *name, DiskList& list)
113{
114 return VERR_NOT_IMPLEMENTED;
115}
116
117} /* namespace pm */
118
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