Cari di RHE Linux 
    RHE Linux User Manual
Daftar Isi
(Sebelumnya) 30 : Chapter 6. Profiling - De ...30 : Index - Developer Guide (Berikutnya)

Developer Guide

Chapter 8.  Documentation Tools

Red Hat Enterprise Linux 6 has two documentation tools available to include documentation with a project. These are Publican and Doxygen.

8.1. Publican

Publican a program is used to publish and process documentation through DocBook XML. In the process of publishing books, it checks the XML to ensure it is valid and in a publishable standard. It is particularly useful for publishing the documentation accompanying a newly created application.

8.1.1. Commands

Publican has a vast number of commands and actions available, all of which can be found in the --help or --man pages. The most common ones are:
build
Converts the XML files into other formats more suitable for documentation (PDF, HTML, HTML-single, for example).
create
Creates a new book, including all the required files as discussed in Section 8.1.3, "Files".
create_brand
Creates a new brand, allowing all books to look the same, as discussed in Section 8.1.6, "Brands".
package
Packages the files of a book into an RPM ready to distribute.

8.1.2. Create a New Document

Use the publican create command to create a new document including all the required files.
There are a number of options available to append to the publican create. These are:
--help
Prints a list of accepted options for the publican create command.
--name Doc_Name
Set the name of the book. Keep in mind that the title must contain no spaces.
--lang Language_Code
If this is not set, the default is en-US. The --lang option sets the xml_lang in the publican.cfg file and creates a directory with this name in the document directory.
--version version
Set the version number of the product the book is about.
--product Product_Name
Set the name of the product the book is about. Keep in mind that this must contain no spaces.
--brand brand
Set the name of a brand to use to keep the look of the documents consistent.
Refer to --help for more options.
Remember to change into the directory the book is to be created in before running publican create. This prevents the files and directories be added to the user's home directory.

8.1.3. Files

When a book is made, a number of files are created in the book's directory. These files are required for the book to be built properly and should not be deleted. They are, however, required to be edited for links (such as chapters) to work, as well as to contain the correct information regarding authors and titles etc. These files are:
publican.cfg
This file configures the build options and always includes the parameters xml_lang (the language the book is in, en-US for example), type (the type of document, a book or a set, for example), and brand (the branding the document uses, found here: Section 8.1.6, "Brands". Red Hat, for example.). There are a number of optional parameters but these should be used cautiously as they can cause problems further on in areas like translation. A full list of these advanced parameters can be found in the Publican User Guide. The publican.cfg file is unlikely to be edited much beyond the initial creation.
book_info.xml
This file is the template of the book. It contains information such as the title, subtitle, author, publication number, and the book's ID number. It also contains the basic Publican information printed at the beginning of each publication with information on the notes, cautions, and warnings as well as a basic stylistic guide. This file will be edited often as every time a book is updated the publication number has to be incremented.
Author_Group.xml
This file is used to store information about the authors and contributors. Once initially set up it is unlikely further editing will be required unless a change of authorship occurs.
Chapter.xml
This file is an example of what the actual content will be. It is created as a place holder but unless it is linked in the Doc_Name.xml (below) it will not appear in the actual book. When writing content for the publication, new XML files are created, named appropriately (ch-publican.xml, for example) and linked in Doc_Name.xml. When the book is built, the content of this file will form the content of the book. This specific file is unlikely to ever be edited but others like it will be edited constantly as content is changed, updated, added to or removed.
Doc_Name.xml
This file is the contents page of the publication. It contains a list of links to the various chapters a book is to contain. It will not actually be called 'Doc_Name' but will have whatever the title of the publication is in it's place (Developer_Guide.xml, for example). This will only be edited when new chapters are added, removed or rearranged. This must remain the same as Doc_Name.ent or the book will not build.
Doc_Name.ent
This file contains a list of local entities. By default YEAR is set to the current year and HOLDER has a reminder to place the copyright owner's name there. As with Doc_Name.xml, this file will not be called 'Doc_Name' but will be replaced with the title of the document (Developer_Guide.ent, for example). This is only likely to be edited once at the beginning of publication or if the copyright owner changes. This must remain the same as Doc_Name.xml or the book will not build.
Revision_History.xml
When publican package is run, the first XML file containing a <revhistory> tag is used to build the RPM revision history.

8.1.3.1. Adding Media to Documentation

Occasionally it may become necessary to add various media to a document in order to illustrate what is being explained.
Images
The images folder is created by publican in the document's directory. Store any images used in the document here. Then when entering an image into the document, link to the image inside the images directory (./images/image1.png, for example).
Code Examples
As time passes and technology changes, a project's documentation will be required to be updated to reflect differences in code. To make this easier, create individual files for each code example in a preferred editor, then save them in a folder called extras in the document's directory. Then, when entering the code sample into the document, link to the file and the folder it is in. This way an example used in several places can be updated only once, and rather than search through a document looking for a specific item to change, all the code examples are located in the one place, saving time and effort.
Arbitrary Files
On occasion there may be a requirement for files not attached to the documentation to be bundled with the RPM (video tutorials, for example). Adding these files to a directory called files in the publication's directory will allow them to be added to the RPM when the book is compiled.
To link to any of these files, use the following XML:
<xi:include parse="text" class="edunwman1" href="extras/fork/fork1.c" xmlns:xi="http://www.w3.org/2001/XInclude" />

8.1.4. Building a Document

In the root directory, first run a test build to ensure that all the XML is correct and acceptable by typing publican build --formats=chosen_format --langs=chosen_language. For example, to build a document in US English and as a single HTML page, run publican build --formats=html-single --langs=en-US. Provided there are no errors the book will be built into the root directory where the pages can be viewed to see if it has the look required. It is recommended to do this regularly in order to make troubleshooting as easy as possible.

Note

When creating a build to test for any bugs in the XML code, sometimes it may be useful to use the --novalid option. This skips over any cross-references and links that point to files or sections of the document that do not yet exist. Instead they are shown as three question marks (???).
There are a number of different formats a document can be published in. These are:
html
An ordinary HTML page with links to new pages for new chapters and sections.
html-single
One long HTML page where the links to new chapters and sections at the top of the page directing the user further down the page, rather than to new page.
html-desktop
One long HTML page where the links to new chapters and sections are in a panel on the left side of the document, directing the user further down the page, rather than to a new page.
man
A man page for Linux, UNIX, and other similar operating systems.
pdf
A PDF file.
test
The XML is validated without actually creating a file for viewing.
txt
A single text file.
epub
An e-book in EPUB format.
eclipse
An Eclipse help plug-in.

8.1.5. Packaging a Publication

Once the documentation is complete and can be built with no errors, run publican package --lang=chosen_language. This will output SRPM packages to tmp/rpm in the document's directory, and binary RPM packages will go to tmp/rpm/noarch in the document's directory. By default, these packages are named productname-title-productnumber-[web]-language-edition-pubsnumber.[build_target].noarch.file_extension with the information for each of these sections coming from publican.cfg.

8.1.6. Brands

Brands are used in a similar way as templates in that they create a level of consistency in appearance, with aspects like matching logos, images and color schemes, across a range of documents. This can be particularly useful when producing several books for the same application or the same bundle of applications.
In order to create a new brand, it must have a name and a language. Run publican create_brand --name=brand --lang=language_code. This will create a folder called publican-brand and place it in the publication's directory. This folder contains the following files:
COPYING
Part of an SRPM package and containing the copyright license and details.
defaults.cfg
Provides default values for the parameters that can be set in publican.cfg. Specifications from this file are applied first before applying those in the publican.cfg file. Therefore, values in the publican.cfg file override those in the defaults.cfg file. It is best used for aspects that are routinely used throughout the documents but still allows writers to change settings.
overrides.cfg
Also provides values for the parameters that can be set in publican-brand.spec. Specifications from this file are applied last, thus overriding both the defaults.cfg and the publican.cfg. It is best used for aspects the writers are not allowed to change.
publican.cfg
This file is similar to the publican.cfg file for a publication in that it configures basic information for the brand, such as version, release number and brand name.
publican-brand.spec
This file is used by the RPM Package Manager to package the publication into an RPM.
README
Part of an SRPM package and providing a brief description of the package.
A subdirectory, named by the language code, is also placed in this directory and contains the following files:
Feedback.xml
This is generated by default to allow readers to leave feedback. Customize it to contain the relevant contact details or a bug reporting process.
Legal_Notice.xml:
Contains copyright information. Edit it to change the details of the chosen copyright license.
Two more subdirectories are within this directory. The images subdirectory contains a number of images of both raster (PNG) and vector (SVG) formats and serve as place holders for various navigation icons that can be changed by replacing the images. The css folder contains overrides.css, which sets the visual style for the brand, overriding those in common.css.
In order to package the new brand ready for distribution, use the publican package command. By default this creates source RPM packages (SRPM Packages) but it can also create binary RPM packages using the option --binary. Packages are named publican-brand-version-release.[build_target].[noarch].file_extension with the required parameters taken from the publican.cfg file.

Note

SRPM packages have the file extension .src.rpm while binary RPM packages have the file extension .rpm
Binary RPM packages include [build_target].noarch before the file extension, where [build_target] represents the operating system and version that the package is built for as set by the os_ver parameter in the publican.cfg file. The noarch element specifies that the package can be installed on any system, regardless of the system architecture.

8.1.7. Building a Website

Publican can also build websites to manage documentation. This is mostly useful when only one person is maintaining the documentation, but where a team is working on the documentation Publican can generate RPM packages of documentation to install on a web server. The website created consists of a homepage, product and version description pages, and the pages for the documentation. In the publication's root directory, Publican creates a configuration file, an SQLite database file, and two subdirectories. There could be many configuration files depending on how many languages the documentation is published in, with a new subdirectory for each language.
Refer to Section 8.1.8, "Documentation" for more information.

8.1.8. Documentation

Publican has comprehensive --man, --help and --help_actions pages accessed from the terminal.
For information on XML including the different tags available, see the DocBook guide, DocBook: the definitive guide by Norman Walsh and Leonard Muellner, found here: http://www.docbook.org/tdg/en/html/docbook and specifically Part II: Reference for a list of all the tags and brief instructions on how to use them.
There is also the comprehensive Publican User Guide accessed online at http://jfearn.fedorapeople.org/en-US/index.html or installed locally with yum install publican-doc.

8.2. Doxygen

Doxygen is a documentation tool that creates reference material both online in HTML and offline in Latex. It does this from a set of documented source files which makes it easy to keep the documentation consistent and correct with the source code.

8.2.1. Doxygen Supported Output and Languages

Doxygen has support for output in:
  • RTF (MS Word)
  • PostScript
  • Hyperlinked PDF
  • Compressed HTML
  • Unix man pages
Doxygen supports the following programming languages:
  • C
  • C++
  • C#
  • Objective -C
  • IDL
  • Java
  • VHDL
  • PHP
  • Python
  • Fortran
  • D

8.2.2. Getting Started

Doxygen uses a configuration file to determine its settings, therefore it is paramount that this be created correctly. Each project requires its own configuration file. The most painless way to create the configuration file is with the command doxygen -g config-file. This creates a template configuration file that can be easily edited. The variable config-file is the name of the configuration file. If it is committed from the command it is called Doxyfile by default. Another useful option while creating the configuration file is the use of a minus sign (-) as the file name. This is useful for scripting as it will cause Doxygen to attempt to read the configuration file from standard input (stdin).
The configuration file consists of a number of variables and tags, similar to a simple Makefile. For example:
TAGNAME = VALUE1 VALUE2...
For the most part these can be left alone but should it be required to edit them refer to the configuration page of the Doxygen documentation website for an extensive explanation of all the tags available. There is also a GUI interface called doxywizard. If this is the preferred method of editing then documentation for this function can be found on the Doxywizard usage page of the Doxygen documentation website.
There are eight tags that are useful to become familiar with.
INPUT
For small projects consisting mainly of C or C++ source and header files it is not required to change anything. However, if the project is large and consists of a source directory or tree, then assign the root directory or directories to the INPUT tag.
FILE_PATTERNS
File patterns (for example, *.cpp or *.h) can be added to this tag allowing only files that match one of the patterns to be parsed.
RECURSIVE
Setting this to yes will allow recursive parsing of a source tree.
EXCLUDE and EXCLUDE_PATTERNS
These are used to further fine-tune the files that are parsed by adding file patterns to avoid. For example, to omit all test directories from a source tree, use EXCLUDE_PATTERNS = */test/*.
EXTRACT_ALL
When this is set to yes, doxygen will pretend that everything in the source files is documented to give an idea of how a fully documented project would look. However, warnings regarding undocumented members will not be generated in this mode; set it back to no when finished to correct this.
SOURCE_BROWSER and INLINE_SOURCES
By setting the SOURCE_BROWSER tag to yes doxygen will generate a cross-reference to analyze a piece of software's definition in its source files with the documentation existing about it. These sources can also be included in the documentation by setting INLINE_SOURCES to yes.

8.2.3. Running Doxygen

Running doxygen config-file creates html, rtf, latex, xml, and / or man directories in whichever directory doxygen is started in, containing the documentation for the corresponding filetype.
HTML OUTPUT
This documentation can be viewed with a HTML browser that supports cascading style sheets (CSS), as well as DHTML and Javascript for some sections. Point the browser (for example, Mozilla, Safari, Konqueror, or Internet Explorer 6) to the index.html in the html directory.
LaTeX OUTPUT
Doxygen writes a Makefile into the latex directory in order to make it easy to first compile the Latex documentation. To do this, use a recent teTeX distribution. What is contained in this directory depends on whether the USE_PDFLATEX is set to no. Where this is true, typing make while in the latex directory generates refman.dvi. This can then be viewed with xdvi or converted to refman.ps by typing make ps. Note that this requires dvips.
There are a number of commands that may be useful. The command make ps_2on1 prints two pages on one physical page. It is also possible to convert to a PDF if a ghostscript interpreter is installed by using the command make pdf. Another valid command is make pdf_2on1. When doing this set PDF_HYPERLINKS and USE_PDFLATEX tags to yes as this will cause Makefile will only contain a target to build refman.pdf directly.
RTF OUTPUT
This file is designed to import into Microsoft Word by combining the RTF output into a single file: refman.rtf. Some information is encoded using fields but this can be shown by selecting all (CTRL+A or Edit -> select all) and then right-click and select the toggle fields option from the drop down menu.
XML OUTPUT
The output into the xml directory consists of a number of files, each compound gathered by doxygen, as well as an index.xml. An XSLT script, combine.xslt, is also created that is used to combine all the XML files into a single file. Along with this, two XML schema files are created, index.xsd for the index file, and compound.xsd for the compound files, which describe the possible elements, their attributes, and how they are structured.
MAN PAGE OUTPUT
The documentation from the man directory can be viewed with the man program after ensuring the manpath has the correct man directory in the man path. Be aware that due to limitations with the man page format, information such as diagrams, cross-references and formulas will be lost.

8.2.4. Documenting the Sources

There are three main steps to document the sources.
  1. First, ensure that EXTRACT_ALL is set to no so warnings are correctly generated and documentation is built properly. This allows doxygen to create documentation for documented members, files, classes and namespaces.
  2. There are two ways this documentation can be created:
    A special documentation block
    This comment block, containing additional marking so Doxygen knows it is part of the documentation, is in either C or C++. It consists of a brief description, or a detailed description. Both of these are optional. What is not optional, however, is the in body description. This then links together all the comment blocks found in the body of the method or function.

    Note

    While more than one brief or detailed description is allowed, this is not recommended as the order is not specified.
    The following will detail the ways in which a comment block can be marked as a detailed description:
    • C-style comment block, starting with two asterisks (*) in the JavaDoc style.
      /** * ... documentation ... */
    • C-style comment block using the Qt style, consisting of an exclamation mark (!) instead of an extra asterisk.
      /*! * ... documentation ... */
    • The beginning asterisks on the documentation lines can be left out in both cases if that is preferred.
    • A blank beginning and end line in C++ also acceptable, with either three forward slashes or two forward slashes and an exclamation mark.
      ////// ... documentation///
      or
      //!//! ... documentation ...//!
    • Alternatively, in order to make the comment blocks more visible a line of asterisks or forward slashes can be used.
      //////////////////////////////////////////////////// ... documentation .../////////////////////////////////////////////////
      or
      /********************************************//** * ... documentation ... ***********************************************/
      Note that the two forwards slashes at the end of the normal comment block start a special comment block.
    There are three ways to add a brief description to documentation.
    • To add a brief description use \brief above one of the comment blocks. This brief section ends at the end of the paragraph and any further paragraphs are the detailed descriptions.
      /*! \brief brief documentation. * brief documentation. * *  detailed documentation. */
    • By setting JAVADOC_AUTOBRIEF to yes, the brief description will only last until the first dot followed by a space or new line. Consequentially limiting the brief description to a single sentence.
      /** Brief documentation. Detailed documentation continues * from here. */
      This can also be used with the above mentioned three-slash comment blocks (///).
    • The third option is to use a special C++ style comment, ensuring this does not span more than one line.
      /// Brief documentation./** Detailed documentation. */
      or
      //! Brief documentation.//! Detailed documentation //! starts here
      The blank line in the above example is required to separate the brief description and the detailed description, and JAVADOC_AUTOBRIEF must to be set to no.
    Examples of how a documented piece of C++ code using the Qt style can be found on the Doxygen documentation website
    It is also possible to have the documentation after members of a file, struct, union, class, or enum. To do this add a < marker in the comment block.\
    int var; /*!< detailed description after the member */
    Or in a Qt style as:
    int var; /**< detailed description after the member */
    or
    int var; //!< detailed description after the member //!<
    or
    int var; ///< detailed description after the member ///<
    For brief descriptions after a member use:
    int var; //!< brief description after the member
    or
    int var; ///< brief description after the member
    Examples of these and how the HTML is produced can be viewed on the Doxygen documentation website
    Documentation at other places
    While it is preferable to place documentation in front of the code it is documenting, at times it is only possible to put it in a different location, especially if a file is to be documented; after all it is impossible to place the documentation in front of a file. This is best avoided unless it is absolutely necessary as it can lead to some duplication of information.
    To do this it is important to have a structural command inside the documentation block. Structural commands start with a backslash (\) or an at-sign (@) for JavaDoc and are followed by one or more parameters.
    /*! \class Test \brief A test class. A more detailed description of class. */
    In the above example the command \class is used. This indicates that the comment block contains documentation for the class 'Test'. Others are:
    • \struct: document a C-struct
    • \union: document a union
    • \enum: document an enumeration type
    • \fn: document a function
    • \var: document a variable, typedef, or enum value
    • \def: document a #define
    • \typedef: document a type definition
    • \file: document a file
    • \namespace: document a namespace
    • \package: document a Java package
    • \interface: document an IDL interface
  3. Next, the contents of a special documentation block is parsed before being written to the HTML and / Latex output directories. This includes:
    1. Special commands are executed.
    2. Any white space and asterisks (*) are removed.
    3. Blank lines are taken as new paragraphs.
    4. Words are linked to their corresponding documentation. Where the word is preceded by a percent sign (%) the percent sign is removed and the word remains.
    5. Where certain patterns are found in the text, links to members are created. Examples of this can be found on the automatic link generation page on the Doxygen documentation website.
    6. When the documentation is for Latex, HTML tags are interpreted and converted to Latex equivalents. A list of supported HTML tags can be found on the HTML commands page on the Doxygen documentation website.

8.2.5. Resources

More information can be found on the Doxygen website.

Appendix

A.1. mallopt

mallopt is a library call that allows a program to change the behavior of the malloc memory allocator.

Example A.1. Allocator heuristics

An allocator has heuristics to determine long versus short lived objects. For the former, it attempts to allocate with mmap. For the later, it attempts to allocate with sbrk.
In order to override these heuristics, set M_MMAP_THRESHOLD.

In multi-threaded applications, the allocator creates multiple arenas in response to lock contention in existing arenas. This can improve the performance significantly for some multi-threaded applications at the cost of an increase in memory usage. To keep this under control, limit the number of arenas that can be created by using the mallopt interface.
The allocator has limits on the number of arenas it can create. For 32bit targets, it will create 2 * # core arenas; for 64bit targets, it will create 8 * # core arenas. mallopt allows the developer to override those limits.

Example A.2. mallopt

To ensure no more than eight arenas are created, issue the following library call:
mallopt (M_ARENA_MAX, 8);

The first argument for mallopt can be:
  • M_MXFAST
  • M_TRIM_THRESHOLD
  • M_TOP_PAD
  • M_MMAP_THRESHOLD
  • M_MMAP_MAX
  • M_CHECK_ACTION
  • M_PERTURB
  • M_ARENA_TEST
  • M_ARENA_MAX
Specific definitions for the above can be found at http://www.makelinux.net/man/3/M/mallopt.

malloc_trim

malloc_trim is a library call that requests the allocator return any unused memory back to the operating system. This is normally automatic when an object is freed. However, in some cases when freeing small objects, glibc might not immediately release the memory back to the operating system. It does this so that the free memory can be used to satisfy upcoming memory allocation requests as it is expensive to allocate from and release memory back to the operating system.

malloc_stats

malloc_stats is used to dump information about the allocator's internal state to stderr. Using mallinfo is similar to this, but it places the state into a structure instead.

Revision History

Revision History
Revision 2-34Tue Feb 19 2013Jacquelynn East
Version for 6.4 GA release.
Revision 2-32Fri Jan 25 2013Jacquelynn East
Updated Developer Toolset section.
Revision 2-7Wed Jul 11 2012Jacquelynn East
Altered Developer Toolset chapter to add more information and remove hard links.
Revision 2-5Mon Jul 09 2012Jacquelynn East
Re-release for Developer Toolset chapter.
Revision 2-3Mon Jun 18 2012Jacquelynn East
Version for the 6.3 GA release. New edition for major changes especially in Eclipse chapters.
Revision 1-46Wed Jun 13 2012Jacquelynn East
Many bugs after doc review.
Revision 1-44Mon May 14 2012Jacquelynn East
BZ#803404.
Revision 1-40Tue Mar 13 2012Jacquelynn East
BZ#722520.
Revision 1-39Wed Mar 07 2012Jacquelynn East
BZ#799076.
Revision 1-38Tue Mar 06 2012Jacquelynn East
BZ#722520.
Revision 1-34Tue Mar 01 2012Jacquelynn East
BZ#722513.
Revision 1-33Wed Feb 29 2012Jacquelynn East
BZ#754173.
Revision 1-31Mon Feb 13 2012Jacquelynn East
BZ#642395.
Revision 1-28Wed Jan 25 2012Jacquelynn East
BZ#722517.
BZ#722504.
BZ#785194.
BZ#785191.
BZ#722520.
BZ#722517.
Revision 1-21Mon Jan 09 2012Jacquelynn East
BZ#754163.
Revision 1-19Mon Dec 12 2011Jacquelynn East
BZ#722510.
Revision 1-18Thu Dec 08 2011Jacquelynn East
BZ#722507.
Revision 1-16Fri Dec 02 2011Jacquelynn East
Release for GA of Red Hat Enterprise Linux 6.2.
(Sebelumnya) 30 : Chapter 6. Profiling - De ...30 : Index - Developer Guide (Berikutnya)