Skip to content

Commit

Permalink
kernel-shark: Fix various compile warnings
Browse files Browse the repository at this point in the history
Those warnings started showing up after adding the "-Wextra"
compiler flag.

Signed-off-by: Yordan Karadzhov <[email protected]>
  • Loading branch information
yordan-karadzhov committed Mar 10, 2024
1 parent 932b147 commit 5b428e3
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 65 deletions.
3 changes: 2 additions & 1 deletion examples/configio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ int main(int argc, char **argv)
struct kshark_config_doc *conf, *filter, *hello;
struct kshark_context *kshark_ctx;
struct kshark_data_stream *stream;
int sd, *ids = NULL, i;
int sd, *ids = NULL;
size_t i;

/* Create a new kshark session. */
kshark_ctx = NULL;
Expand Down
4 changes: 2 additions & 2 deletions examples/datafilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const char *default_file = "trace.dat";

int main(int argc, char **argv)
{
size_t i, sd, n_rows, n_tasks, n_evts, count;
size_t i, n_rows, n_tasks, n_evts, count;
struct kshark_context *kshark_ctx;
struct kshark_data_stream *stream;
struct kshark_entry **data = NULL;
int *pids, *evt_ids;
int sd, *pids, *evt_ids;
char *entry_str;

/* Create a new kshark session. */
Expand Down
2 changes: 1 addition & 1 deletion examples/datahisto.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void dump_bin(struct kshark_trace_histo *histo, int bin, int sd,

void dump_histo(struct kshark_trace_histo *histo, int sd, const char *type, int val)
{
size_t bin;
int bin;

for (bin = 0; bin < histo->n_bins; ++bin)
dump_bin(histo, bin, sd, type, val);
Expand Down
42 changes: 22 additions & 20 deletions src/libkshark-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ kshark_data_collection_alloc(struct kshark_context *kshark_ctx,
temp->type = COLLECTION_IGNORE;
}

for (i = first + margin; i < end; ++i) {
for (i = first + margin; i < (size_t) end; ++i) {
if (!cond(kshark_ctx, data[i], sd, values)) {
/*
* The entry is irrelevant for this collection.
Expand Down Expand Up @@ -161,9 +161,8 @@ kshark_data_collection_alloc(struct kshark_context *kshark_ctx,

/* Keep adding entries until the "next" record. */
for (j = i + 1;
j != end && last_vis_entry->next != data[j];
j++)
;
j != (size_t) end && last_vis_entry->next != data[j];
j++);

/*
* If the number of added entries is smaller than the
Expand Down Expand Up @@ -322,8 +321,9 @@ map_collection_request_init(const struct kshark_entry_collection *col,
bool front, size_t *end)
{
int col_index_flag;
ssize_t col_index;
size_t col_index;
size_t req_end;
ssize_t ret;

if (req->next || col->size == 0) {
fprintf(stderr,
Expand All @@ -338,19 +338,17 @@ map_collection_request_init(const struct kshark_entry_collection *col,
* Find the first Resume Point of the collection which is equal or
* greater than the first index of this request.
*/
col_index = map_collection_index_from_source(col,
req->first,
&col_index_flag);
ret = map_collection_index_from_source(col, req->first, &col_index_flag);
if (ret == KS_EMPTY_BIN) {
/* Empty collection. */
goto do_nothing;
}
col_index = ret;

/*
* The value of "col_index" is ambiguous. Use the "col_index_flag" to
* deal with all possible cases.
*/
if (col_index == KS_EMPTY_BIN) {
/* Empty collection. */
goto do_nothing;
}

if (col_index_flag == COLLECTION_AFTER) {
/*
* This request starts after the end of interval "col_index".
Expand Down Expand Up @@ -436,20 +434,22 @@ map_collection_back_request(const struct kshark_entry_collection *col,
struct kshark_entry_request *req)
{
size_t req_first, req_end;
ssize_t col_index;
size_t col_index;
int req_count;
ssize_t ret;

col_index = map_collection_request_init(col, req, false, &req_end);
if (col_index == KS_EMPTY_BIN)
ret = map_collection_request_init(col, req, false, &req_end);
if (ret == KS_EMPTY_BIN)
return 0;
col_index = ret;

/*
* Now loop over the intervals of the collection going backwards till
* the end of the inputted request and create a separate request for
* each of those interest.
*/
req_count = 1;
while (col_index >= 0 && req_end <= col->break_points[col_index]) {
while (req_end <= col->break_points[col_index]) {
if (req_end >= col->resume_points[col_index]) {
/*
* The last entry of the original request is inside
Expand Down Expand Up @@ -519,12 +519,14 @@ map_collection_front_request(const struct kshark_entry_collection *col,
struct kshark_entry_request *req)
{
size_t req_first, req_end;
ssize_t col_index;
size_t col_index;
int req_count;
ssize_t ret;

col_index = map_collection_request_init(col, req, true, &req_end);
if (col_index == KS_EMPTY_BIN)
ret = map_collection_request_init(col, req, true, &req_end);
if (ret == KS_EMPTY_BIN)
return 0;
col_index = ret;

/*
* Now loop over the intervals of the collection going forwards till
Expand Down
6 changes: 4 additions & 2 deletions src/libkshark-configio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,8 @@ static bool kshark_event_filter_to_json(struct kshark_data_stream *stream,
json_object *jfilter_data, *jname;
struct kshark_hash_id *filter;
char *name_str;
int i, *ids;
int *ids;
size_t i;

filter = kshark_get_filter(stream, filter_type);
if (!filter)
Expand Down Expand Up @@ -1283,7 +1284,8 @@ static bool kshark_filter_array_to_json(struct kshark_hash_id *filter,
struct json_object *jobj)
{
json_object *jfilter_data, *jpid = NULL;
int i, *ids;
int *ids;
size_t i;

/*
* If this Json document already contains a description of the filter,
Expand Down
7 changes: 3 additions & 4 deletions src/libkshark-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ void kshark_hash_id_remove(struct kshark_hash_id *hash, int id)
void kshark_hash_id_clear(struct kshark_hash_id *hash)
{
struct kshark_hash_id_item *item, *next;
size_t size;
int i;
size_t i, size;

if (!hash || ! hash->hash)
return;
Expand Down Expand Up @@ -211,8 +210,8 @@ static int compare_ids(const void* a, const void* b)
int *kshark_hash_ids(struct kshark_hash_id *hash)
{
struct kshark_hash_id_item *item;
size_t size = hash_size(hash);
int count = 0, i;
size_t i, size = hash_size(hash);
int count = 0;
int *ids;

if (!hash->count)
Expand Down
20 changes: 10 additions & 10 deletions src/libkshark-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static bool ksmodel_histo_alloc(struct kshark_trace_histo *histo, size_t n)
}

static void ksmodel_set_in_range_bining(struct kshark_trace_histo *histo,
size_t n, int64_t min, int64_t max,
int n, int64_t min, int64_t max,
bool force_in_range)
{
int64_t corrected_range, delta_range, range = max - min;
Expand All @@ -110,7 +110,7 @@ static void ksmodel_set_in_range_bining(struct kshark_trace_histo *histo,
}

/* The size of the bin must be >= 1, hence the range must be >= n. */
if (range < n) {
if (range < (int64_t) n) {
range = n;
max = min + n;
}
Expand Down Expand Up @@ -266,10 +266,10 @@ static size_t ksmodel_set_upper_edge(struct kshark_trace_histo *histo)
}

static void ksmodel_set_next_bin_edge(struct kshark_trace_histo *histo,
size_t bin, size_t last_row)
int bin, size_t last_row)
{
int64_t time_min, time_max;
size_t next_bin = bin + 1;
int next_bin = bin + 1;
ssize_t row;

/* Calculate the beginning and the end of the next bin. */
Expand Down Expand Up @@ -463,12 +463,12 @@ size_t ksmodel_bin_count(struct kshark_trace_histo *histo, int bin)
* @param histo: Input location for the model descriptor.
* @param n: Number of bins to shift.
*/
void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)
void ksmodel_shift_forward(struct kshark_trace_histo *histo, int n)
{
size_t last_row = 0;
int bin;

if (!histo->data_size)
if (!histo->data_size || histo->n_bins <= 0)
return;

if (histo->map[UOB(histo)] == KS_EMPTY_BIN) {
Expand Down Expand Up @@ -541,12 +541,12 @@ void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n)
* @param histo: Input location for the model descriptor.
* @param n: Number of bins to shift.
*/
void ksmodel_shift_backward(struct kshark_trace_histo *histo, size_t n)
void ksmodel_shift_backward(struct kshark_trace_histo *histo, int n)
{
size_t last_row = 0;
int bin;

if (!histo->data_size)
if (!histo->data_size || histo->n_bins <= 0)
return;

if (histo->map[LOB(histo)] == KS_EMPTY_BIN) {
Expand Down Expand Up @@ -649,7 +649,7 @@ void ksmodel_jump_to(struct kshark_trace_histo *histo, int64_t ts)
static void ksmodel_zoom(struct kshark_trace_histo *histo,
double r, int mark, bool zoom_in)
{
size_t range, min, max, delta_min;
int64_t range, min, max, delta_min;
double delta_tot;

if (!histo->data_size)
Expand All @@ -668,7 +668,7 @@ static void ksmodel_zoom(struct kshark_trace_histo *histo,
* Avoid overzooming. If needed, adjust the Scale factor to a the value
* which provides bin_size >= 5.
*/
if (zoom_in && (size_t) (range * (1. - r)) < histo->n_bins * 5)
if (zoom_in && (int64_t) (range * (1. - r)) < (int64_t) histo->n_bins * 5)
r = 1. - (histo->n_bins * 5.) / range;

/*
Expand Down
4 changes: 2 additions & 2 deletions src/libkshark-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void ksmodel_fill(struct kshark_trace_histo *histo,

size_t ksmodel_bin_count(struct kshark_trace_histo *histo, int bin);

void ksmodel_shift_forward(struct kshark_trace_histo *histo, size_t n);
void ksmodel_shift_forward(struct kshark_trace_histo *histo, int n);

void ksmodel_shift_backward(struct kshark_trace_histo *histo, size_t n);
void ksmodel_shift_backward(struct kshark_trace_histo *histo, int n);

void ksmodel_jump_to(struct kshark_trace_histo *histo, int64_t ts);

Expand Down
3 changes: 1 addition & 2 deletions src/libkshark-tepdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static int get_next_pid(struct kshark_data_stream *stream,
ret = tep_read_number_field(get_sched_next(stream),
record->data, &val);

return ret ? : val;
return ret ? : (int) val;
}

static void register_command(struct kshark_data_stream *stream,
Expand Down Expand Up @@ -312,7 +312,6 @@ static ssize_t get_records(struct kshark_context *kshark_ctx,
count = 0;
cpu_list[cpu] = NULL;
temp_next = &cpu_list[cpu];

rec = tracecmd_read_cpu_first(kshark_get_tep_input(stream), cpu);
while (rec) {
*temp_next = temp_rec = calloc(1, sizeof(*temp_rec));
Expand Down
28 changes: 18 additions & 10 deletions src/libkshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,14 +1370,15 @@ void kshark_clear_all_filters(struct kshark_context *kshark_ctx,
size_t n_entries)
{
struct kshark_data_stream *stream;
int *stream_ids, i;
int *stream_ids, sd;
size_t i;

for (i = 0; i < n_entries; ++i)
set_all_visible(&data[i]->visible);

stream_ids = kshark_all_streams(kshark_ctx);
for (i = 0; i < kshark_ctx->n_streams; i++) {
stream = kshark_get_data_stream(kshark_ctx, stream_ids[i]);
for (sd = 0; sd < kshark_ctx->n_streams; sd++) {
stream = kshark_get_data_stream(kshark_ctx, stream_ids[sd]);
stream->filter_is_applied = false;
}

Expand Down Expand Up @@ -1902,10 +1903,13 @@ void kshark_set_clock_offset(struct kshark_context *kshark_ctx,
kshark_data_qsort(entries, size);
}

static int first_in_time_entry(struct kshark_entry_data_set *buffer, int n_buffers, size_t *count)
static int first_in_time_entry(struct kshark_entry_data_set *buffer,
size_t n_buffers,
ssize_t *count)
{
int64_t t_min = INT64_MAX;
int i, min = -1;
int min = -1;
size_t i;

for (i = 0; i < n_buffers; ++i) {
if (count[i] == buffer[i].n_rows)
Expand All @@ -1930,10 +1934,11 @@ static int first_in_time_entry(struct kshark_entry_data_set *buffer, int n_buffe
* responsible for freeing the elements of the outputted array.
*/
struct kshark_entry **
kshark_merge_data_entries(struct kshark_entry_data_set *buffers, int n_buffers)
kshark_merge_data_entries(struct kshark_entry_data_set *buffers, size_t n_buffers)
{
struct kshark_entry **merged_data;
size_t i, tot = 0, count[n_buffers];
ssize_t count[n_buffers];
size_t i, tot = 0;
int i_first;

if (n_buffers < 2) {
Expand Down Expand Up @@ -2078,7 +2083,9 @@ ssize_t kshark_append_all_entries(struct kshark_context *kshark_ctx,
merged_data);
}

static int first_in_time_row(struct kshark_matrix_data_set *buffers, int n_buffers, size_t *count)
static int first_in_time_row(struct kshark_matrix_data_set *buffers,
int n_buffers,
ssize_t *count)
{
int64_t t_min = INT64_MAX;
int i, min = -1;
Expand Down Expand Up @@ -2107,10 +2114,11 @@ static int first_in_time_row(struct kshark_matrix_data_set *buffers, int n_buffe
* matrix.
*/
struct kshark_matrix_data_set
kshark_merge_data_matrices(struct kshark_matrix_data_set *buffers, int n_buffers)
kshark_merge_data_matrices(struct kshark_matrix_data_set *buffers, size_t n_buffers)
{
struct kshark_matrix_data_set merged_data;
size_t i, tot = 0, count[n_buffers];
ssize_t count[n_buffers];
size_t i, tot = 0;
int i_first;
bool status;

Expand Down
6 changes: 3 additions & 3 deletions src/libkshark.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ struct kshark_entry_collection {
int *values;

/** The suze of the array of matching condition values. */
int n_val;
size_t n_val;

/**
* Array of indexes defining the beginning of each individual data
Expand Down Expand Up @@ -1071,7 +1071,7 @@ struct kshark_entry_data_set {

struct kshark_entry **
kshark_merge_data_entries(struct kshark_entry_data_set *buffers,
int n_buffers);
size_t n_buffers);

ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx,
struct kshark_entry ***data_rows);
Expand Down Expand Up @@ -1111,7 +1111,7 @@ struct kshark_matrix_data_set {

struct kshark_matrix_data_set
kshark_merge_data_matrices(struct kshark_matrix_data_set *buffers,
int n_buffers);
size_t n_buffers);

/**
* Structure used to store the data of a kshark_entry plus one additional
Expand Down
Loading

0 comments on commit 5b428e3

Please sign in to comment.