src/os/aix/vm/libperfstat_aix.cpp

Fri, 06 Sep 2013 20:16:09 +0200

author
simonis
date
Fri, 06 Sep 2013 20:16:09 +0200
changeset 6465
666e6ce3976c
parent 0
f90c822e73f8
permissions
-rw-r--r--

8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
Reviewed-by: kvn

     1 /*
     2  * Copyright 2012, 2013 SAP AG. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "runtime/arguments.hpp"
    26 #include "libperfstat_aix.hpp"
    28 // For dlopen and friends
    29 #include <fcntl.h>
    31 // handle to the libperfstat
    32 static void* g_libhandle = NULL;
    34 // whether initialization worked
    35 static bool g_initialized = false;
    38 typedef int (*fun_perfstat_cpu_total_t) (perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
    39                                          int sizeof_userbuff, int desired_number);
    41 typedef int (*fun_perfstat_memory_total_t) (perfstat_id_t *name, perfstat_memory_total_t* userbuff,
    42                                             int sizeof_userbuff, int desired_number);
    44 typedef void (*fun_perfstat_reset_t) ();
    46 static fun_perfstat_cpu_total_t     g_fun_perfstat_cpu_total = NULL;
    47 static fun_perfstat_memory_total_t  g_fun_perfstat_memory_total = NULL;
    48 static fun_perfstat_reset_t         g_fun_perfstat_reset = NULL;
    50 bool libperfstat::init() {
    52   if (g_initialized) {
    53     return true;
    54   }
    56   g_initialized = false;
    58   // dynamically load the libperfstat porting library.
    59   g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW);
    60   if (!g_libhandle) {
    61     if (Verbose) {
    62       fprintf(stderr, "Cannot load libperfstat.a (dlerror: %s)", dlerror());
    63     }
    64     return false;
    65   }
    67   // resolve function pointers
    69 #define RESOLVE_FUN_NO_ERROR(name) \
    70   g_fun_##name = (fun_##name##_t) dlsym(g_libhandle, #name);
    72 #define RESOLVE_FUN(name) \
    73   RESOLVE_FUN_NO_ERROR(name) \
    74   if (!g_fun_##name) { \
    75     if (Verbose) { \
    76       fprintf(stderr, "Cannot resolve " #name "() from libperfstat.a\n" \
    77                       "   (dlerror: %s)", dlerror()); \
    78       } \
    79     return false; \
    80   }
    82   RESOLVE_FUN(perfstat_cpu_total);
    83   RESOLVE_FUN(perfstat_memory_total);
    84   RESOLVE_FUN(perfstat_reset);
    86   g_initialized = true;
    88   return true;
    89 }
    91 void libperfstat::cleanup() {
    93   g_initialized = false;
    95   if (g_libhandle) {
    96     dlclose(g_libhandle);
    97     g_libhandle = NULL;
    98   }
   100   g_fun_perfstat_cpu_total = NULL;
   101   g_fun_perfstat_memory_total = NULL;
   102   g_fun_perfstat_reset = NULL;
   103 }
   105 int libperfstat::perfstat_memory_total(perfstat_id_t *name,
   106                                        perfstat_memory_total_t* userbuff,
   107                                        int sizeof_userbuff, int desired_number) {
   108   assert(g_initialized, "libperfstat not initialized");
   109   assert(g_fun_perfstat_memory_total, "");
   110   return g_fun_perfstat_memory_total(name, userbuff, sizeof_userbuff, desired_number);
   111 }
   113 int libperfstat::perfstat_cpu_total(perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
   114                                     int sizeof_userbuff, int desired_number) {
   115   assert(g_initialized, "libperfstat not initialized");
   116   assert(g_fun_perfstat_cpu_total, "");
   117   return g_fun_perfstat_cpu_total(name, userbuff, sizeof_userbuff, desired_number);
   118 }
   120 void libperfstat::perfstat_reset() {
   121   assert(g_initialized, "libperfstat not initialized");
   122   assert(g_fun_perfstat_reset, "");
   123   g_fun_perfstat_reset();
   124 }

mercurial