Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
PerfCounterMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* PerfCounterMng.cc (C) 2000-2017 */
9/* */
10/* */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15#include "arcane/utils/PerfCounterMng.h"
16
17#include <iostream>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
34extern "C++" int
36{
37#ifndef WIN32
38 /* return cpu frequency in MHZ as read in /proc/cpuinfo */
39 float ffreq = 0;
40 int r = 0;
41 char* rr = NULL;
42 FILE* fdes = fopen("/proc/cpuinfo", "r");
43 char buff[256];
44 int bufflength = 256;
45 do {
46 rr = fgets(buff, bufflength, fdes);
47 r = sscanf(buff, "cpu MHz : %f\n", &ffreq);
48 if (r == 1) {
49 break;
50 }
51 } while (rr != NULL);
52
53 fclose(fdes);
54
55 int ifreq = (int)ffreq;
56 return ifreq;
57#else
58 std::cerr << "getCpuFreq not functionnal under win\n";
59 return 1;
60#endif
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66} // namespace Arcane
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
int arcaneGetCpuBaseFrequency()
Returns the CPU frequency in MHz.