Various adjustments
[pstop.git] / performance_schema / file_summary_by_instance / file_summary_by_instance_row.go
index 0f36edd..7c70f3b 100644 (file)
@@ -8,6 +8,8 @@ import (
        "log"
        "regexp"
        "sort"
+       //      "strconv"
+       "time"
 
        "github.com/sjmudd/pstop/lib"
 )
@@ -46,18 +48,18 @@ CREATE TABLE `file_summary_by_instance` (
 type file_summary_by_instance_row struct {
        FILE_NAME string
 
-       COUNT_STAR  int
-       COUNT_READ  int
-       COUNT_WRITE int
-       COUNT_MISC  int
+       COUNT_STAR  uint64
+       COUNT_READ  uint64
+       COUNT_WRITE uint64
+       COUNT_MISC  uint64
 
-       SUM_TIMER_WAIT  int
-       SUM_TIMER_READ  int
-       SUM_TIMER_WRITE int
-       SUM_TIMER_MISC  int
+       SUM_TIMER_WAIT  uint64
+       SUM_TIMER_READ  uint64
+       SUM_TIMER_WRITE uint64
+       SUM_TIMER_MISC  uint64
 
-       SUM_NUMBER_OF_BYTES_READ  int
-       SUM_NUMBER_OF_BYTES_WRITE int
+       SUM_NUMBER_OF_BYTES_READ  uint64
+       SUM_NUMBER_OF_BYTES_WRITE uint64
 }
 
 // represents a table or set of rows
@@ -164,23 +166,20 @@ func (t file_summary_by_instance_rows) totals() file_summary_by_instance_row {
 
 // clean up the given path reducing redundant stuff and return the clean path
 func cleanup_path(path string) string {
-       //     foo/../bar --> bar       perl: $new =~ s{[^/]+/\.\./}{/};
-       //     foo/./bar  --> foo/bar   perl: $new =~ s{/\./}{};
+       //     foo/../bar --> foo/bar   perl: $new =~ s{[^/]+/\.\./}{/};
+       //     /./        --> /         perl: $new =~ s{/\./}{};
        //     //         --> /         perl: $new =~ s{//}{/};
        const (
-               double_slash_re        = `//`
-               slash_dot_slash_re     = `/\./`
+               one_or_the_other_re    = `/(\.)?/`
                slash_dot_dot_slash_re = `[^/]+/\.\./`
        )
+       r1 := regexp.MustCompile(one_or_the_other_re)
+       r2 := regexp.MustCompile(slash_dot_dot_slash_re)
+
        for {
                orig_path := path
-
-               r := regexp.MustCompile(double_slash_re)
-               path = r.ReplaceAllString(path, "")
-               r = regexp.MustCompile(slash_dot_slash_re)
-               path = r.ReplaceAllString(path, "")
-               r = regexp.MustCompile(slash_dot_dot_slash_re)
-               path = r.ReplaceAllString(path, "")
+               path = r1.ReplaceAllString(path, "/")
+               path = r2.ReplaceAllString(path, "/")
                if orig_path == path { // no change so give up
                        break
                }
@@ -193,25 +192,34 @@ func cleanup_path(path string) string {
 // This simpler name may also merge several different filenames into one.
 func (t file_summary_by_instance_row) simple_name(global_variables map[string]string) string {
        const (
-               auto_cnf_re  = `/auto\.cnf$`
-               binlog_re    = `/binlog\.(\d{6}|index)$`
-               charset_re   = `/share/charsets/Index\.xml$`
-               db_opt_re    = `/db\.opt$`
-               error_msg_re = `/share/[^/]+/errmsg\.sys$`
-               ibdata_re    = `/ibdata\d+$`
-               redo_log_re  = `/ib_logfile\d+$`
-               pid_file_re  = `/[^/]+\.pid$`
-               //              relay_log_re  = `/mysql-relay-bin.(\d{6}|index)$`
-               relative_path_re = `^\.\./`
+               auto_cnf_re      = `/auto\.cnf$`
+               binlog_re        = `/binlog\.(\d{6}|index)$`
+               charset_re       = `/share/charsets/Index\.xml$`
                current_dir_re   = `^\./`
+               db_opt_re        = `/db\.opt$`
+               encoded_re       = `@(\d{4})` // FIXME - add me to catch @0024 --> $ for example
+               error_msg_re     = `/share/[^/]+/errmsg\.sys$`
+               ibdata_re        = `/ibdata\d+$`
+               part_table_re    = `(.+)#P#p\d+`
+               pid_file_re      = `/[^/]+\.pid$`
+               redo_log_re      = `/ib_logfile\d+$`
+               relative_path_re = `^\.\./`
                slowlog_re       = `/slowlog$`
                table_file_re    = `/([^/]+)/([^/]+)\.(frm|ibd|MYD|MYI|CSM|CSV|par)$`
                temp_table_re    = `#sql-[0-9_]+`
-               part_table_re    = `(.+)#P#p\d+`
        )
 
        path := t.FILE_NAME
 
+       // FIXME and make this work.
+       //      re4 := regexp.MustCompile(encoded_re)
+       //      if m4 := re4.FindStringSubmatch(path); m4 != nil {
+       //              if value, err := strconv.ParseInt(m4[1], 16, 16); err != nil {
+       //                      // missing replace @.... with char(value) in path
+       //
+       //              }
+       //      }
+
        // this should probably be ordered from most expected regexp to least
        re := regexp.MustCompile(table_file_re)
        if m1 := re.FindStringSubmatch(path); m1 != nil {
@@ -276,6 +284,7 @@ func (t file_summary_by_instance_row) simple_name(global_variables map[string]st
 // Convert the imported "table" to a merged one with merged data.
 // Combine all entries with the same "FILE_NAME" by adding their values.
 func merge_by_table_name(orig file_summary_by_instance_rows, global_variables map[string]string) file_summary_by_instance_rows {
+       start := time.Now()
        t := make(file_summary_by_instance_rows, 0, len(orig))
 
        m := make(map[string]file_summary_by_instance_row)
@@ -305,6 +314,7 @@ func merge_by_table_name(orig file_summary_by_instance_rows, global_variables ma
                t = append(t, row)
        }
 
+       lib.Logger.Println("merge_by_table_name() took:", time.Duration(time.Since(start)).String())
        return t
 }
 
@@ -314,6 +324,7 @@ func merge_by_table_name(orig file_summary_by_instance_rows, global_variables ma
 // - change FILE_NAME into a more descriptive value.
 func select_fsbi_rows(dbh *sql.DB) file_summary_by_instance_rows {
        var t file_summary_by_instance_rows
+       start := time.Now()
 
        sql := "SELECT FILE_NAME, COUNT_STAR, SUM_TIMER_WAIT, COUNT_READ, SUM_TIMER_READ, SUM_NUMBER_OF_BYTES_READ, COUNT_WRITE, SUM_TIMER_WRITE, SUM_NUMBER_OF_BYTES_WRITE, COUNT_MISC, SUM_TIMER_MISC FROM file_summary_by_instance"
 
@@ -334,6 +345,7 @@ func select_fsbi_rows(dbh *sql.DB) file_summary_by_instance_rows {
        if err := rows.Err(); err != nil {
                log.Fatal(err)
        }
+       lib.Logger.Println("select_fsbi_rows() took:", time.Duration(time.Since(start)).String())
 
        return t
 }