# OS_InitFunctionCost

## Syntax

  `#include <nitro/os.h>`
  `void OS_InitFunctionCost( void* buf, u32 size );`

## Arguments

`buf` | Function cost calculation buffer
`size` | Size of the function cost calculation buffer.

## Return Values

None.

## Description

Sets the buffer that will be used for function cost calculation, and begins the function cost calculation. After function cost calculation settings are made by calling this function, calculation status will be Enabled.(This is the status after the `OS_EnableFunctionCost` function is called.))

In order for a function to be calculated, it must be compiled with the `profile` feature on. (When you compile with `TWL_PROFILE=TRUE`, at compile time the `-profile` option will be attached, and the profile feature will be on.)

To enable features that are related to function cost calculation, at link time you must include `libos.FUNCTIONCOST.a` (in the thumb version `libos.FUNCTIONCOST.thumb.a`). To do this, specify `TWL_PROFILE_TYPE=FUNCTIONCOST` as a `make` option. You may also write it in the `makefile`. However, in the final ROM version (FINALROM) library, it will not do anything.

An information header used for function cost calculations (`sizeof(OSFunctionCostInfo) - sizeof(OSFunctionCost)` bytes) is stored in the front of the buffer `buf`. When the function is called, the size of information stored will be `sizeof(OSFunctionCost)` bytes.

If you are using a thread system, buffers are independent for each thread. Therefore, if you want to store cost calculations, you will have to define a separate buffer in each thread.

To aggregate and display calculation results, aggregate them with the `OS_CalcStatistics` or `OS_CalcThreadStatistics` function, then call the `OS_DumpStatistics` function.

## See Also

`OS_CalcStatistics`
`OS_CalcThreadStatics`
`OS_DumpStatistics`

## Revision History

2004/06/02 Changed description of the `make` options
2004/05/18 Initial version.

CONFIDENTIAL