< prev index next >

src/share/vm/runtime/os.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. 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  *


 830       }
 831     }
 832   }
 833 }
 834 
 835 void os::print_cpu_info(outputStream* st) {
 836   // cpu
 837   st->print("CPU:");
 838   st->print("total %d", os::processor_count());
 839   // It's not safe to query number of active processors after crash
 840   // st->print("(active %d)", os::active_processor_count()); but we can
 841   // print the initial number of active processors.
 842   // We access the raw value here because the assert in the accessor will
 843   // fail if the crash occurs before initialization of this value.
 844   st->print(" (initial active %d)", _initial_active_processor_count);
 845   st->print(" %s", VM_Version::cpu_features());
 846   st->cr();
 847   pd_print_cpu_info(st);
 848 }
 849 
 850 void os::print_date_and_time(outputStream *st) {
 851   const int secs_per_day  = 86400;
 852   const int secs_per_hour = 3600;
 853   const int secs_per_min  = 60;
 854 
 855   time_t tloc;
 856   (void)time(&tloc);
 857   st->print("time: %s", ctime(&tloc));  // ctime adds newline.






 858 
 859   double t = os::elapsedTime();
 860   // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in
 861   //       Linux. Must be a bug in glibc ? Workaround is to round "t" to int
 862   //       before printf. We lost some precision, but who cares?
 863   int eltime = (int)t;  // elapsed time in seconds
 864 
 865   // print elapsed time in a human-readable format:
 866   int eldays = eltime / secs_per_day;
 867   int day_secs = eldays * secs_per_day;
 868   int elhours = (eltime - day_secs) / secs_per_hour;
 869   int hour_secs = elhours * secs_per_hour;
 870   int elmins = (eltime - day_secs - hour_secs) / secs_per_min;
 871   int minute_secs = elmins * secs_per_min;
 872   int elsecs = (eltime - day_secs - hour_secs - minute_secs);
 873   st->print_cr("elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs);
 874 }
 875 
 876 // moved from debug.cpp (used to be find()) but still called from there
 877 // The verbose parameter is only set by the debug code in one case


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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  *


 830       }
 831     }
 832   }
 833 }
 834 
 835 void os::print_cpu_info(outputStream* st) {
 836   // cpu
 837   st->print("CPU:");
 838   st->print("total %d", os::processor_count());
 839   // It's not safe to query number of active processors after crash
 840   // st->print("(active %d)", os::active_processor_count()); but we can
 841   // print the initial number of active processors.
 842   // We access the raw value here because the assert in the accessor will
 843   // fail if the crash occurs before initialization of this value.
 844   st->print(" (initial active %d)", _initial_active_processor_count);
 845   st->print(" %s", VM_Version::cpu_features());
 846   st->cr();
 847   pd_print_cpu_info(st);
 848 }
 849 
 850 void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
 851   const int secs_per_day  = 86400;
 852   const int secs_per_hour = 3600;
 853   const int secs_per_min  = 60;
 854 
 855   time_t tloc;
 856   (void)time(&tloc);
 857   st->print("time: %s", ctime(&tloc));  // ctime adds newline.
 858 
 859   struct tm tz;
 860   if (localtime_pd(&tloc, &tz) != NULL) {
 861     ::strftime(buf, buflen, "%Z", &tz);
 862     st->print_cr("timezone: %s", buf);
 863   }
 864 
 865   double t = os::elapsedTime();
 866   // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in
 867   //       Linux. Must be a bug in glibc ? Workaround is to round "t" to int
 868   //       before printf. We lost some precision, but who cares?
 869   int eltime = (int)t;  // elapsed time in seconds
 870 
 871   // print elapsed time in a human-readable format:
 872   int eldays = eltime / secs_per_day;
 873   int day_secs = eldays * secs_per_day;
 874   int elhours = (eltime - day_secs) / secs_per_hour;
 875   int hour_secs = elhours * secs_per_hour;
 876   int elmins = (eltime - day_secs - hour_secs) / secs_per_min;
 877   int minute_secs = elmins * secs_per_min;
 878   int elsecs = (eltime - day_secs - hour_secs - minute_secs);
 879   st->print_cr("elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs);
 880 }
 881 
 882 // moved from debug.cpp (used to be find()) but still called from there
 883 // The verbose parameter is only set by the debug code in one case


< prev index next >