src/os/aix/vm/libperfstat_aix.cpp

changeset 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/aix/vm/libperfstat_aix.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,124 @@
     1.4 +/*
     1.5 + * Copyright 2012, 2013 SAP AG. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "runtime/arguments.hpp"
    1.29 +#include "libperfstat_aix.hpp"
    1.30 +
    1.31 +// For dlopen and friends
    1.32 +#include <fcntl.h>
    1.33 +
    1.34 +// handle to the libperfstat
    1.35 +static void* g_libhandle = NULL;
    1.36 +
    1.37 +// whether initialization worked
    1.38 +static bool g_initialized = false;
    1.39 +
    1.40 +
    1.41 +typedef int (*fun_perfstat_cpu_total_t) (perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
    1.42 +                                         int sizeof_userbuff, int desired_number);
    1.43 +
    1.44 +typedef int (*fun_perfstat_memory_total_t) (perfstat_id_t *name, perfstat_memory_total_t* userbuff,
    1.45 +                                            int sizeof_userbuff, int desired_number);
    1.46 +
    1.47 +typedef void (*fun_perfstat_reset_t) ();
    1.48 +
    1.49 +static fun_perfstat_cpu_total_t     g_fun_perfstat_cpu_total = NULL;
    1.50 +static fun_perfstat_memory_total_t  g_fun_perfstat_memory_total = NULL;
    1.51 +static fun_perfstat_reset_t         g_fun_perfstat_reset = NULL;
    1.52 +
    1.53 +bool libperfstat::init() {
    1.54 +
    1.55 +  if (g_initialized) {
    1.56 +    return true;
    1.57 +  }
    1.58 +
    1.59 +  g_initialized = false;
    1.60 +
    1.61 +  // dynamically load the libperfstat porting library.
    1.62 +  g_libhandle = dlopen("/usr/lib/libperfstat.a(shr_64.o)", RTLD_MEMBER | RTLD_NOW);
    1.63 +  if (!g_libhandle) {
    1.64 +    if (Verbose) {
    1.65 +      fprintf(stderr, "Cannot load libperfstat.a (dlerror: %s)", dlerror());
    1.66 +    }
    1.67 +    return false;
    1.68 +  }
    1.69 +
    1.70 +  // resolve function pointers
    1.71 +
    1.72 +#define RESOLVE_FUN_NO_ERROR(name) \
    1.73 +  g_fun_##name = (fun_##name##_t) dlsym(g_libhandle, #name);
    1.74 +
    1.75 +#define RESOLVE_FUN(name) \
    1.76 +  RESOLVE_FUN_NO_ERROR(name) \
    1.77 +  if (!g_fun_##name) { \
    1.78 +    if (Verbose) { \
    1.79 +      fprintf(stderr, "Cannot resolve " #name "() from libperfstat.a\n" \
    1.80 +                      "   (dlerror: %s)", dlerror()); \
    1.81 +      } \
    1.82 +    return false; \
    1.83 +  }
    1.84 +
    1.85 +  RESOLVE_FUN(perfstat_cpu_total);
    1.86 +  RESOLVE_FUN(perfstat_memory_total);
    1.87 +  RESOLVE_FUN(perfstat_reset);
    1.88 +
    1.89 +  g_initialized = true;
    1.90 +
    1.91 +  return true;
    1.92 +}
    1.93 +
    1.94 +void libperfstat::cleanup() {
    1.95 +
    1.96 +  g_initialized = false;
    1.97 +
    1.98 +  if (g_libhandle) {
    1.99 +    dlclose(g_libhandle);
   1.100 +    g_libhandle = NULL;
   1.101 +  }
   1.102 +
   1.103 +  g_fun_perfstat_cpu_total = NULL;
   1.104 +  g_fun_perfstat_memory_total = NULL;
   1.105 +  g_fun_perfstat_reset = NULL;
   1.106 +}
   1.107 +
   1.108 +int libperfstat::perfstat_memory_total(perfstat_id_t *name,
   1.109 +                                       perfstat_memory_total_t* userbuff,
   1.110 +                                       int sizeof_userbuff, int desired_number) {
   1.111 +  assert(g_initialized, "libperfstat not initialized");
   1.112 +  assert(g_fun_perfstat_memory_total, "");
   1.113 +  return g_fun_perfstat_memory_total(name, userbuff, sizeof_userbuff, desired_number);
   1.114 +}
   1.115 +
   1.116 +int libperfstat::perfstat_cpu_total(perfstat_id_t *name, perfstat_cpu_total_t* userbuff,
   1.117 +                                    int sizeof_userbuff, int desired_number) {
   1.118 +  assert(g_initialized, "libperfstat not initialized");
   1.119 +  assert(g_fun_perfstat_cpu_total, "");
   1.120 +  return g_fun_perfstat_cpu_total(name, userbuff, sizeof_userbuff, desired_number);
   1.121 +}
   1.122 +
   1.123 +void libperfstat::perfstat_reset() {
   1.124 +  assert(g_initialized, "libperfstat not initialized");
   1.125 +  assert(g_fun_perfstat_reset, "");
   1.126 +  g_fun_perfstat_reset();
   1.127 +}

mercurial