3863N/A/*
3863N/A * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
3863N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3863N/A *
3863N/A * This code is free software; you can redistribute it and/or modify it
3863N/A * under the terms of the GNU General Public License version 2 only, as
3863N/A * published by the Free Software Foundation.
3863N/A *
3863N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3863N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3863N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3863N/A * version 2 for more details (a copy is included in the LICENSE file that
3863N/A * accompanied this code).
3863N/A *
3863N/A * You should have received a copy of the GNU General Public License version
3863N/A * 2 along with this work; if not, write to the Free Software Foundation,
3863N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3863N/A *
3863N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3863N/A * or visit www.oracle.com if you need additional information or have any
3863N/A * questions.
3863N/A *
3863N/A */
3863N/A
3863N/A#ifndef SHARE_VM_SERVICES_MEM_REPORTER_HPP
3863N/A#define SHARE_VM_SERVICES_MEM_REPORTER_HPP
3863N/A
3863N/A#include "runtime/mutexLocker.hpp"
3863N/A#include "services/memBaseline.hpp"
3863N/A#include "services/memTracker.hpp"
3863N/A#include "utilities/ostream.hpp"
3863N/A
3863N/A/*
3863N/A * MemBaselineReporter reports data to this outputer class,
3863N/A * ReportOutputer is responsible for format, store and redirect
3863N/A * the data to the final destination.
3863N/A */
3863N/Aclass BaselineOutputer : public StackObj {
3863N/A public:
3863N/A // start to report memory usage in specified scale.
3863N/A // if report_diff = true, the reporter reports baseline comparison
3863N/A // information.
3863N/A
3863N/A virtual void start(size_t scale, bool report_diff = false) = 0;
3863N/A // Done reporting
3863N/A virtual void done() = 0;
3863N/A
3863N/A /* report baseline summary information */
3863N/A virtual void total_usage(size_t total_reserved,
3863N/A size_t total_committed) = 0;
3863N/A virtual void num_of_classes(size_t classes) = 0;
3863N/A virtual void num_of_threads(size_t threads) = 0;
3863N/A
3863N/A virtual void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) = 0;
3863N/A
3863N/A /* report baseline summary comparison */
3863N/A virtual void diff_total_usage(size_t total_reserved,
3863N/A size_t total_committed,
3863N/A int reserved_diff,
3863N/A int committed_diff) = 0;
3863N/A virtual void diff_num_of_classes(size_t classes, int diff) = 0;
3863N/A virtual void diff_num_of_threads(size_t threads, int diff) = 0;
3863N/A
3863N/A virtual void diff_thread_info(size_t stack_reserved, size_t stack_committed,
3863N/A int stack_reserved_diff, int stack_committed_diff) = 0;
3863N/A
3863N/A
3863N/A /*
3863N/A * memory summary by memory types.
3863N/A * for each memory type, following summaries are reported:
3863N/A * - reserved amount, committed amount
3863N/A * - malloc'd amount, malloc count
3863N/A * - arena amount, arena count
3863N/A */
3863N/A
3863N/A // start reporting memory summary by memory type
3863N/A virtual void start_category_summary() = 0;
3863N/A
3863N/A virtual void category_summary(MEMFLAGS type, size_t reserved_amt,
3863N/A size_t committed_amt,
3863N/A size_t malloc_amt, size_t malloc_count,
3863N/A size_t arena_amt, size_t arena_count) = 0;
3863N/A
3863N/A virtual void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
3863N/A size_t cur_committed_amt,
3863N/A size_t cur_malloc_amt, size_t cur_malloc_count,
3863N/A size_t cur_arena_amt, size_t cur_arena_count,
3863N/A int reserved_diff, int committed_diff, int malloc_diff,
3863N/A int malloc_count_diff, int arena_diff,
3863N/A int arena_count_diff) = 0;
3863N/A
3863N/A virtual void done_category_summary() = 0;
3863N/A
4064N/A virtual void start_virtual_memory_map() = 0;
4064N/A virtual void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc) = 0;
4064N/A virtual void committed_memory_region(address base, address end, size_t size, address pc) = 0;
4064N/A virtual void done_virtual_memory_map() = 0;
4064N/A
3863N/A /*
3863N/A * Report callsite information
3863N/A */
3863N/A virtual void start_callsite() = 0;
3863N/A virtual void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count) = 0;
3863N/A virtual void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt) = 0;
3863N/A
3863N/A virtual void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
3863N/A int malloc_diff, int malloc_count_diff) = 0;
3863N/A virtual void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
3863N/A int reserved_diff, int committed_diff) = 0;
3863N/A
3863N/A virtual void done_callsite() = 0;
3863N/A
3863N/A // return current scale in "KB", "MB" or "GB"
3863N/A static const char* memory_unit(size_t scale);
3863N/A};
3863N/A
3863N/A/*
3863N/A * This class reports processed data from a baseline or
3863N/A * the changes between the two baseline.
3863N/A */
3863N/Aclass BaselineReporter : public StackObj {
3863N/A private:
3863N/A BaselineOutputer& _outputer;
3863N/A size_t _scale;
3863N/A
3863N/A public:
3863N/A // construct a reporter that reports memory usage
3863N/A // in specified scale
3863N/A BaselineReporter(BaselineOutputer& outputer, size_t scale = K):
3863N/A _outputer(outputer) {
3863N/A _scale = scale;
3863N/A }
3863N/A virtual void report_baseline(const MemBaseline& baseline, bool summary_only = false);
3863N/A virtual void diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
3863N/A bool summary_only = false);
3863N/A
3863N/A void set_scale(size_t scale);
3863N/A size_t scale() const { return _scale; }
3863N/A
3863N/A private:
3863N/A void report_summaries(const MemBaseline& baseline);
4064N/A void report_virtual_memory_map(const MemBaseline& baseline);
3863N/A void report_callsites(const MemBaseline& baseline);
3863N/A
3863N/A void diff_summaries(const MemBaseline& cur, const MemBaseline& prev);
3863N/A void diff_callsites(const MemBaseline& cur, const MemBaseline& prev);
3863N/A
3863N/A // calculate memory size in current memory scale
3863N/A size_t amount_in_current_scale(size_t amt) const;
3863N/A // diff two unsigned values in current memory scale
3863N/A int diff_in_current_scale(size_t value1, size_t value2) const;
3863N/A // diff two unsigned value
3863N/A int diff(size_t value1, size_t value2) const;
3863N/A};
3863N/A
3863N/A/*
3863N/A * tty output implementation. Native memory tracking
3863N/A * DCmd uses this outputer.
3863N/A */
3863N/Aclass BaselineTTYOutputer : public BaselineOutputer {
3863N/A private:
3863N/A size_t _scale;
3863N/A
3863N/A size_t _num_of_classes;
3863N/A size_t _num_of_threads;
3863N/A size_t _thread_stack_reserved;
3863N/A size_t _thread_stack_committed;
3863N/A
3863N/A int _num_of_classes_diff;
3863N/A int _num_of_threads_diff;
3863N/A int _thread_stack_reserved_diff;
3863N/A int _thread_stack_committed_diff;
3863N/A
3863N/A outputStream* _output;
3863N/A
3863N/A public:
3863N/A BaselineTTYOutputer(outputStream* st) {
3863N/A _scale = K;
3863N/A _num_of_classes = 0;
3863N/A _num_of_threads = 0;
3863N/A _thread_stack_reserved = 0;
3863N/A _thread_stack_committed = 0;
3863N/A _num_of_classes_diff = 0;
3863N/A _num_of_threads_diff = 0;
3863N/A _thread_stack_reserved_diff = 0;
3863N/A _thread_stack_committed_diff = 0;
3863N/A _output = st;
3863N/A }
3863N/A
3863N/A // begin reporting memory usage in specified scale
3863N/A void start(size_t scale, bool report_diff = false);
3863N/A // done reporting
3863N/A void done();
3863N/A
3863N/A // total memory usage
3863N/A void total_usage(size_t total_reserved,
3863N/A size_t total_committed);
3863N/A // report total loaded classes
3863N/A void num_of_classes(size_t classes) {
3863N/A _num_of_classes = classes;
3863N/A }
3863N/A
3863N/A void num_of_threads(size_t threads) {
3863N/A _num_of_threads = threads;
3863N/A }
3863N/A
3863N/A void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) {
3863N/A _thread_stack_reserved = stack_reserved_amt;
3863N/A _thread_stack_committed = stack_committed_amt;
3863N/A }
3863N/A
3863N/A void diff_total_usage(size_t total_reserved,
3863N/A size_t total_committed,
3863N/A int reserved_diff,
3863N/A int committed_diff);
3863N/A
3863N/A void diff_num_of_classes(size_t classes, int diff) {
3863N/A _num_of_classes = classes;
3863N/A _num_of_classes_diff = diff;
3863N/A }
3863N/A
3863N/A void diff_num_of_threads(size_t threads, int diff) {
3863N/A _num_of_threads = threads;
3863N/A _num_of_threads_diff = diff;
3863N/A }
3863N/A
3863N/A void diff_thread_info(size_t stack_reserved_amt, size_t stack_committed_amt,
3863N/A int stack_reserved_diff, int stack_committed_diff) {
3863N/A _thread_stack_reserved = stack_reserved_amt;
3863N/A _thread_stack_committed = stack_committed_amt;
3863N/A _thread_stack_reserved_diff = stack_reserved_diff;
3863N/A _thread_stack_committed_diff = stack_committed_diff;
3863N/A }
3863N/A
3863N/A /*
3863N/A * Report memory summary categoriuzed by memory types.
3863N/A * For each memory type, following summaries are reported:
3863N/A * - reserved amount, committed amount
3863N/A * - malloc-ed amount, malloc count
3863N/A * - arena amount, arena count
3863N/A */
3863N/A // start reporting memory summary by memory type
3863N/A void start_category_summary();
3863N/A void category_summary(MEMFLAGS type, size_t reserved_amt, size_t committed_amt,
3863N/A size_t malloc_amt, size_t malloc_count,
3863N/A size_t arena_amt, size_t arena_count);
3863N/A
3863N/A void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
3863N/A size_t cur_committed_amt,
3863N/A size_t cur_malloc_amt, size_t cur_malloc_count,
3863N/A size_t cur_arena_amt, size_t cur_arena_count,
3863N/A int reserved_diff, int committed_diff, int malloc_diff,
3863N/A int malloc_count_diff, int arena_diff,
3863N/A int arena_count_diff);
3863N/A
3863N/A void done_category_summary();
3863N/A
4064N/A // virtual memory map
4064N/A void start_virtual_memory_map();
4064N/A void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc);
4064N/A void committed_memory_region(address base, address end, size_t size, address pc);
4064N/A void done_virtual_memory_map();
4064N/A
4064N/A
3863N/A /*
3863N/A * Report callsite information
3863N/A */
3863N/A void start_callsite();
3863N/A void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count);
3863N/A void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt);
3863N/A
3863N/A void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
3863N/A int malloc_diff, int malloc_count_diff);
3863N/A void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
3863N/A int reserved_diff, int committed_diff);
3863N/A
3863N/A void done_callsite();
3863N/A};
3863N/A
3863N/A
3863N/A#endif // SHARE_VM_SERVICES_MEM_REPORTER_HPP